]> Git Repo - linux.git/commitdiff
libbpf: fix GCC8 warning for strncpy
authorAndrii Nakryiko <[email protected]>
Tue, 2 Jul 2019 15:16:20 +0000 (08:16 -0700)
committerDaniel Borkmann <[email protected]>
Wed, 3 Jul 2019 09:52:45 +0000 (11:52 +0200)
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 <[email protected]>
Cc: Magnus Karlsson <[email protected]>
Acked-by: Yonghong Song <[email protected]>
Acked-by: Magnus Karlsson <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
tools/lib/bpf/xsk.c

index bf15a80a37c27ca0d236b4f898b95a170409999a..b33740221b7e7bd86c4f1286c8010fe587f79fc6 100644 (file)
@@ -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;
This page took 0.057992 seconds and 4 git commands to generate.