diff options
author | Daniel Wagner <wagi@monom.org> | 2021-04-05 17:18:16 +0200 |
---|---|---|
committer | Daniel Wagner <wagi@monom.org> | 2021-04-05 17:27:49 +0200 |
commit | 3dbcc963a66d43e4ac51c97de4fe116ec72eb9f6 (patch) | |
tree | 26fdaf60f3f73d3abfcffdeed11bc8372cffe12e /plugins | |
parent | ac25945c7a2cdf891cb3aaf386ea7d829add9ad0 (diff) | |
download | connman-3dbcc963a66d43e4ac51c97de4fe116ec72eb9f6.tar.gz |
ethernet: Copy interfance names obeying lengths rules
gcc points out the destination buffer has the same size the specified
bound for the string:
warning: ‘__builtin_stpncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
Let's make sure we do not overflow the buffer (should not happen as
the names are provide by the kernel and hence should fit).
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ethernet.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/plugins/ethernet.c b/plugins/ethernet.c index ed4208ad..6146b1c0 100644 --- a/plugins/ethernet.c +++ b/plugins/ethernet.c @@ -73,7 +73,7 @@ static int get_vlan_vid(const char *ifname) return -errno; vifr.cmd = GET_VLAN_VID_CMD; - stpncpy(vifr.device1, ifname, sizeof(vifr.device1)); + stpncpy(vifr.device1, ifname, sizeof(vifr.device1) - 1); if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0) vid = vifr.u.VID; @@ -99,14 +99,16 @@ static int get_dsa_port(const char *ifname) return -errno; memset(&ifr, 0, sizeof(ifr)); - stpncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + stpncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); /* check if it is a vlan and get physical interface name*/ vifr.cmd = GET_VLAN_REALDEV_NAME_CMD; - stpncpy(vifr.device1, ifname, sizeof(vifr.device1)); + stpncpy(vifr.device1, ifname, sizeof(vifr.device1) - 1); - if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0) - stpncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name)); + if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0) { + stpncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name) - 1); + ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; + } /* get driver info */ drvinfocmd.cmd = ETHTOOL_GDRVINFO; |