misc: fix possible strncpy truncation bug
Spotted by compiler warning:
../include/private/misc.h:93:9: warning: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 15 [-Wstringop-truncation]
93 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use IFNAMSIZ size to fix this.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
diff --git a/include/private/misc.h b/include/private/misc.h
index ac2a747..f6fb23f 100644
--- a/include/private/misc.h
+++ b/include/private/misc.h
@@ -90,7 +90,7 @@
if (sock == -1)
return -errno;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIFINDEX, &ifr);
close(sock);
if (ret == -1) {