[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ8uoz37Ukj1qaZre1-=Rm3GZkkxGW8zxQ85fg5YLHaMWXNp3g@mail.gmail.com>
Date: Tue, 2 Jul 2019 18:38:32 +0200
From: Magnus Karlsson <magnus.karlsson@...il.com>
To: Y Song <ys114321@...il.com>
Cc: Andrii Nakryiko <andriin@...com>,
Andrii Nakryiko <andrii.nakryiko@...il.com>,
bpf <bpf@...r.kernel.org>, netdev <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...com>,
Daniel Borkmann <daniel@...earbox.net>,
Magnus Karlsson <magnus.karlsson@...el.com>
Subject: Re: [PATCH v2 bpf-next] libbpf: fix GCC8 warning for strncpy
On Tue, Jul 2, 2019 at 6:11 PM Y Song <ys114321@...il.com> wrote:
>
> On Tue, Jul 2, 2019 at 8:17 AM Andrii Nakryiko <andriin@...com> wrote:
> >
> > 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.
> >
> > Cc: Magnus Karlsson <magnus.karlsson@...el.com>
> > Signed-off-by: Andrii Nakryiko <andriin@...com>
>
> Acked-by: Yonghong Song <yhs@...com>
Acked-by: Magnus Karlsson <magnus.karlsson@...el.com>
>
> > ---
> > tools/lib/bpf/xsk.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > 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)
> >
> > 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;
> > --
> > 2.17.1
> >
Powered by blists - more mailing lists