Skip to content

Commit b78248c

Browse files
authored
[vs] avoid non null terminated string stored in ifr_name (sonic-net#560)
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 <[email protected]>
1 parent cda854a commit b78248c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

vslib/src/sai_vs_hostintf.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ int vs_create_tap_device(
786786

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

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

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

@@ -819,7 +819,7 @@ int vs_set_dev_mac_address(
819819

820820
struct ifreq ifr;
821821

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

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

@@ -920,7 +920,7 @@ int ifup(
920920

921921
memset(&ifr, 0, sizeof ifr);
922922

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

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

@@ -986,7 +986,7 @@ int promisc(const char *dev)
986986

987987
memset(&ifr, 0, sizeof ifr);
988988

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

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

@@ -1030,7 +1030,7 @@ int vs_set_dev_mtu(
10301030

10311031
struct ifreq ifr;
10321032

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

10351035
ifr.ifr_mtu = mtu;
10361036

0 commit comments

Comments
 (0)