mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
lsqeth: Copy interface name correctly
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 <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user