All of lore.kernel.org
 help / color / mirror / Atom feed
From: Magnus Karlsson <magnus.karlsson@gmail.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: bpf <bpf@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	kernel-team@fb.com, Magnus Karlsson <magnus.karlsson@intel.com>
Subject: Re: [PATCH bpf-next] libbpf: silence GCC8 warning about string truncation
Date: Wed, 24 Jul 2019 15:27:38 +0200	[thread overview]
Message-ID: <CAJ8uoz17j9hzDFaYXRmLc0ziC5mwRCAYvvjmCkfUKHbMtcAwcQ@mail.gmail.com> (raw)
In-Reply-To: <20190723220127.1815913-1-andriin@fb.com>

On Wed, Jul 24, 2019 at 4:33 AM Andrii Nakryiko <andriin@fb.com> wrote:
>
> Despite a proper NULL-termination after strncpy(..., ..., IFNAMSIZ - 1),
> GCC8 still complains about *expected* string truncation:
>
>   xsk.c:330:2: error: 'strncpy' output may be truncated copying 15 bytes
>   from a string of length 15 [-Werror=stringop-truncation]
>     strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1);
>
> This patch gets rid of the issue altogether by using memcpy instead.
> There is no performance regression, as strncpy will still copy and fill
> all of the bytes anyway.

Let us make GCC8 happy then :-). Thanks Andrii.

Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

> Cc: Magnus Karlsson <magnus.karlsson@intel.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>  tools/lib/bpf/xsk.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index 5007b5d4fd2c..65f5dd556f99 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -327,7 +327,7 @@ 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 - 1);
> +       memcpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1);
>         ifr.ifr_name[IFNAMSIZ - 1] = '\0';
>         err = ioctl(fd, SIOCETHTOOL, &ifr);
>         if (err && errno != EOPNOTSUPP) {
> @@ -517,7 +517,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
>                 err = -errno;
>                 goto out_socket;
>         }
> -       strncpy(xsk->ifname, ifname, IFNAMSIZ - 1);
> +       memcpy(xsk->ifname, ifname, IFNAMSIZ - 1);
>         xsk->ifname[IFNAMSIZ - 1] = '\0';
>
>         err = xsk_set_xdp_socket_config(&xsk->config, usr_config);
> --
> 2.17.1
>

  reply	other threads:[~2019-07-24 13:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 22:01 [PATCH bpf-next] libbpf: silence GCC8 warning about string truncation Andrii Nakryiko
2019-07-24 13:27 ` Magnus Karlsson [this message]
2019-07-24 20:43 ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJ8uoz17j9hzDFaYXRmLc0ziC5mwRCAYvvjmCkfUKHbMtcAwcQ@mail.gmail.com \
    --to=magnus.karlsson@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.