Skip to content

Commit

Permalink
fd-net-device: Fix -Werror=stringop-truncation with GCC 8. Using IFNA…
Browse files Browse the repository at this point in the history
…MSIZ - 1 is safe because in all cases the dest structure is initialized with 0.
  • Loading branch information
natale-p committed Jun 6, 2018
1 parent b401974 commit 24a89f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/fd-net-device/helper/emu-fd-net-device-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ EmuFdNetDeviceHelper::SetFileDescriptor (Ptr<FdNetDevice> device) const
//
struct ifreq ifr;
bzero (&ifr, sizeof(ifr));
strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ);
strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ - 1);

NS_LOG_LOGIC ("Getting interface index");
int32_t rc = ioctl (fd, SIOCGIFINDEX, &ifr);
Expand Down
10 changes: 5 additions & 5 deletions src/fd-net-device/helper/tap-device-creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SetIpv4 (const char *deviceName, const char *ip, const char *netmask)
// Set the IP address of the new interface/device.
//
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);

sin = (struct sockaddr_in*) &ifr.ifr_addr;
inet_pton(AF_INET, ip, &sin->sin_addr);
Expand All @@ -136,7 +136,7 @@ SetIpv4 (const char *deviceName, const char *ip, const char *netmask)
// Set the net mask of the new interface/device
//
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);

sin = (struct sockaddr_in*) &ifr.ifr_netmask;
inet_pton(AF_INET, netmask, &sin->sin_addr);
Expand All @@ -158,7 +158,7 @@ SetIpv6 (const char* deviceName, const char *ip, int netprefix)

int sock = socket(AF_INET6, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);

ABORT_IF (ioctl (sock, SIOGIFINDEX, &ifr) == -1,
"Could not get interface index", true);
Expand Down Expand Up @@ -206,7 +206,7 @@ SetUp (char *deviceName)
int sock = socket(AF_INET, SOCK_DGRAM, 0);

memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);

ABORT_IF (ioctl (sock, SIOCGIFFLAGS, &ifr) == -1,
"Could not get flags for interface", true);
Expand Down Expand Up @@ -248,7 +248,7 @@ CreateTap (char *deviceName, const char *mac, const int ifftap, const int iffpi,
//
if (*deviceName)
{
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ);
strncpy(ifr.ifr_name, deviceName, IFNAMSIZ - 1);
}


Expand Down

0 comments on commit 24a89f3

Please sign in to comment.