From 83106991aba1983589f268bf53b1d3ab543209f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Thu, 18 Oct 2018 16:13:34 +0200 Subject: [PATCH] lsqeth: Copy interface name correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IFNAMSIZ is the maximum buffer size for an interface name, including its terminating zero byte. [1] strncpy() should therefore only copy a size of 'IFNAMSIZ - 1' and the destination string should then be null-terminated properly. Use util_strlcpy() to correctly copy the string and get rid of the followin GCC8 compile warning: In function ‘ethtool_checksumming’, inlined from ‘process_sysfs_attribute’ at lsqeth.c:333:5, inlined from ‘print_device’ at lsqeth.c:468:3: lsqeth.c:171:2: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncat ion] strncpy(ifr.ifr_name, if_name, IFNAMSIZ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [1]: https://www.gnu.org/software/libc/manual/html_node/Interface-Naming.html Signed-off-by: Jan Höppner --- zconf/qeth/lsqeth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zconf/qeth/lsqeth.c b/zconf/qeth/lsqeth.c index 0e08350d..c58d39d6 100644 --- a/zconf/qeth/lsqeth.c +++ b/zconf/qeth/lsqeth.c @@ -168,7 +168,7 @@ static void ethtool_checksumming(char *buf, const char *if_name) fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) errx(EXIT_FAILURE, "Internal error: cannot get SOCK_DGRAM socket"); - strncpy(ifr.ifr_name, if_name, IFNAMSIZ); + util_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ); val.cmd = ETHTOOL_GRXCSUM; ifr.ifr_data = (void *)&val; rc = ioctl(fd, SIOCETHTOOL, &ifr);