From 50a63f31b6d2dec99c5af87ae70a14e015772f8f Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Tue, 2 Jul 2019 08:16:20 -0700 Subject: [PATCH] libbpf: fix GCC8 warning for strncpy 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 Cc: Magnus Karlsson Acked-by: Yonghong Song Acked-by: Magnus Karlsson Signed-off-by: Daniel Borkmann --- src/xsk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xsk.c b/src/xsk.c index bf15a80..b337402 100644 --- a/src/xsk.c +++ b/src/xsk.c @@ -327,7 +327,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;