diff options
author | Jiri Pirko <jiri@nvidia.com> | 2022-11-24 15:49:19 +0100 |
---|---|---|
committer | Jiri Pirko <jiri@nvidia.com> | 2022-11-24 15:50:27 +0100 |
commit | 5147be02262dbd18cb7283ff660a8169eaa88b8a (patch) | |
tree | 6fe24db7c93d64c5a8d6fe5533dcef0835e51fa0 | |
parent | ffc6a52bd285a476b547312012078af69220574b (diff) | |
download | libteam-5147be02262dbd18cb7283ff660a8169eaa88b8a.tar.gz |
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>
-rw-r--r-- | include/private/misc.h | 2 |
1 files changed, 1 insertions, 1 deletions
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 @@ static inline int ifname2ifindex(uint32_t *p_ifindex, char *ifname) 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) { |