Skip to content

Commit

Permalink
[vs] avoid non null terminated string stored in ifr_name (sonic-net#560)
Browse files Browse the repository at this point in the history
gcc-8 generates the following error

sai_vs_hostintf.cpp:822:12: error: 'char* strncpy(char*, const char*, size_t)' specified bound 16 equals destination size [-Werror=stringop-truncation]

Signed-off-by: Wataru Ishida <ishida@nel-america.com>
  • Loading branch information
ishidawataru authored Feb 11, 2020
1 parent cda854a commit b78248c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vslib/src/sai_vs_hostintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ int vs_create_tap_device(

ifr.ifr_flags = (short int)flags; // IFF_TUN or IFF_TAP, IFF_NO_PI

strncpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);

int err = ioctl(fd, TUNSETIFF, (void *) &ifr);

Expand Down Expand Up @@ -819,7 +819,7 @@ int vs_set_dev_mac_address(

struct ifreq ifr;

strncpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);

memcpy(ifr.ifr_hwaddr.sa_data, mac, 6);

Expand Down Expand Up @@ -920,7 +920,7 @@ int ifup(

memset(&ifr, 0, sizeof ifr);

strncpy(ifr.ifr_name, dev , IFNAMSIZ);
strncpy(ifr.ifr_name, dev , IFNAMSIZ-1);

int err = ioctl(s, SIOCGIFFLAGS, &ifr);

Expand Down Expand Up @@ -986,7 +986,7 @@ int promisc(const char *dev)

memset(&ifr, 0, sizeof ifr);

strncpy(ifr.ifr_name, dev , IFNAMSIZ);
strncpy(ifr.ifr_name, dev , IFNAMSIZ-1);

int err = ioctl(s, SIOCGIFFLAGS, &ifr);

Expand Down Expand Up @@ -1030,7 +1030,7 @@ int vs_set_dev_mtu(

struct ifreq ifr;

strncpy(ifr.ifr_name, name, IFNAMSIZ);
strncpy(ifr.ifr_name, name, IFNAMSIZ-1);

ifr.ifr_mtu = mtu;

Expand Down

0 comments on commit b78248c

Please sign in to comment.