diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-07-02 11:16:20 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-07-03 05:52:45 -0400 |
commit | cdfc7f888c2a355b01308e97c6df108f1c2b64e8 (patch) | |
tree | e5af226c6107e531e09f61aad19520ec392cf483 | |
parent | a3ce685dd01a786fa5bc388e47d0066a4f842591 (diff) |
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 <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>
-rw-r--r-- | tools/lib/bpf/xsk.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index bf15a80a37c2..b33740221b7e 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c | |||
@@ -327,7 +327,8 @@ static int xsk_get_max_queues(struct xsk_socket *xsk) | |||
327 | 327 | ||
328 | channels.cmd = ETHTOOL_GCHANNELS; | 328 | channels.cmd = ETHTOOL_GCHANNELS; |
329 | ifr.ifr_data = (void *)&channels; | 329 | ifr.ifr_data = (void *)&channels; |
330 | strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ); | 330 | strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1); |
331 | ifr.ifr_name[IFNAMSIZ - 1] = '\0'; | ||
331 | err = ioctl(fd, SIOCETHTOOL, &ifr); | 332 | err = ioctl(fd, SIOCETHTOOL, &ifr); |
332 | if (err && errno != EOPNOTSUPP) { | 333 | if (err && errno != EOPNOTSUPP) { |
333 | ret = -errno; | 334 | ret = -errno; |