summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-07-02 08:16:20 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-07-26 09:10:43 +0200
commitba38126fbd973264d4c4c35c937c13de511097f6 (patch)
tree0bf503de360d76dcbde8597222c66e9fde571888
parentc352c3e84b6e795f8ee8055f5f5152bba6ac9508 (diff)
downloadlinux-stable-ba38126fbd973264d4c4c35c937c13de511097f6.tar.gz
linux-stable-ba38126fbd973264d4c4c35c937c13de511097f6.tar.bz2
linux-stable-ba38126fbd973264d4c4c35c937c13de511097f6.zip
libbpf: fix GCC8 warning for strncpy
[ Upstream commit cdfc7f888c2a355b01308e97c6df108f1c2b64e8 ] GCC8 started emitting warning about using strncpy with number of bytes exactly equal destination size, which is generally unsafe, as can lead to non-zero terminated string being copied. Use IFNAMSIZ - 1 as number of bytes to ensure name is always zero-terminated. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Cc: Magnus Karlsson <magnus.karlsson@intel.com> Acked-by: Yonghong Song <yhs@fb.com> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--tools/lib/bpf/xsk.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 38667b62f1fe..8a7a05bc657d 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -337,7 +337,8 @@ static int xsk_get_max_queues(struct xsk_socket *xsk)
channels.cmd = ETHTOOL_GCHANNELS;
ifr.ifr_data = (void *)&channels;
- strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ);
+ strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1);
+ ifr.ifr_name[IFNAMSIZ - 1] = '\0';
err = ioctl(fd, SIOCETHTOOL, &ifr);
if (err && errno != EOPNOTSUPP) {
ret = -errno;