From 3dbcc963a66d43e4ac51c97de4fe116ec72eb9f6 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 5 Apr 2021 17:18:16 +0200 Subject: ethernet: Copy interfance names obeying lengths rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- plugins/ethernet.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'plugins') 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; -- cgit v1.2.1