[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPpH65zGO02uQyWQXXq6Yg_zsZcVZg+4-KWfRo_q3iACHr6s_Q@mail.gmail.com>
Date: Tue, 21 Apr 2020 21:38:38 +0200
From: Andrea Claudi <aclaudi@...hat.com>
To: Jamal Hadi Salim <jhs@...atatu.com>
Cc: Stephen Hemminger <stephen@...workplumber.org>,
linux-netdev <netdev@...r.kernel.org>,
David Ahern <dsahern@...il.com>, daniel@...earbox.net,
Jamal Hadi Salim <hadi@...atatu.com>
Subject: Re: [PATCH iproute2 1/1] bpf: Fix segfault when custom pinning is used
On Tue, Apr 21, 2020 at 8:05 PM Jamal Hadi Salim <jhs@...atatu.com> wrote:
>
> From: Jamal Hadi Salim <hadi@...atatu.com>
>
> Fixes: c0325b06382 ("bpf: replace snprintf with asprintf when dealing with long buffers")
>
> Signed-off-by: Jamal Hadi Salim <jhs@...atatu.com>
> ---
> lib/bpf.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/lib/bpf.c b/lib/bpf.c
> index 10cf9bf4..cf636c9e 100644
> --- a/lib/bpf.c
> +++ b/lib/bpf.c
> @@ -1509,12 +1509,12 @@ out:
> static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx,
> const char *todo)
> {
> - char *tmp = NULL;
> + char tmp[PATH_MAX] = {};
> char *rem = NULL;
> char *sub;
> int ret;
>
> - ret = asprintf(&tmp, "%s/../", bpf_get_work_dir(ctx->type));
> + ret = sprintf(tmp, "%s/../", bpf_get_work_dir(ctx->type));
> if (ret < 0) {
> fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
> goto out;
> @@ -1547,7 +1547,6 @@ static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx,
> ret = 0;
> out:
> free(rem);
> - free(tmp);
> return ret;
> }
>
> --
> 2.20.1
>
Hi Jamal,
Are you sure this fixes your issue? I think asprintf could segfault
only if ctx is null, but this case is not addressed in your patch.
I remember that Stephen asked me to use asprintf to avoid allocating
huge buffers on stack; anyway I've no objection to sprintf, if needed.
Andrea
Powered by blists - more mailing lists