public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber•org>
To: Jamal Hadi Salim <jhs@mojatatu•com>
Cc: netdev@vger•kernel.org, dsahern@gmail•com, aclaudi@redhat•com,
	daniel@iogearbox•net, asmadeus@codewreck•org,
	Jamal Hadi Salim <hadi@mojatatu•com>
Subject: Re: [PATCH iproute2 v2 1/2] bpf: Fix segfault when custom pinning is used
Date: Wed, 22 Apr 2020 09:35:31 -0700	[thread overview]
Message-ID: <20200422093531.4d9364c9@hermes.lan> (raw)
In-Reply-To: <20200422102808.9197-2-jhs@emojatatu.com>

On Wed, 22 Apr 2020 06:28:07 -0400
Jamal Hadi Salim <jhs@mojatatu•com> wrote:

> From: Jamal Hadi Salim <hadi@mojatatu•com>
> 

This is not a sufficient commit message. You need to describe what the
problem is and why this fixes it.


> Fixes: c0325b06382 ("bpf: replace snprintf with asprintf when dealing with long buffers")
> 
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu•com>
> ---
>  lib/bpf.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/bpf.c b/lib/bpf.c
> index 10cf9bf4..656cad02 100644
> --- a/lib/bpf.c
> +++ b/lib/bpf.c
> @@ -1509,15 +1509,15 @@ out:
>  static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx,
>  				const char *todo)
>  {
> -	char *tmp = NULL;
> +	char tmp[PATH_MAX] = {};

Initializing the whole string to 0 is over kill here.

>  	char *rem = NULL;
>  	char *sub;
>  	int ret;
>  
> -	ret = asprintf(&tmp, "%s/../", bpf_get_work_dir(ctx->type));
> +	ret = snprintf(tmp, PATH_MAX, "%s/../", bpf_get_work_dir(ctx->type));

snprintf will never return -1.

>  	if (ret < 0) {
> -		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
> -		goto out;
> +		fprintf(stderr, "snprintf failed: %s\n", strerror(errno));
> +		return ret;
>  	}
>  
>  	ret = asprintf(&rem, "%s/", todo);
> @@ -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;
>  }
>  

This patch needs to be reworked.

  parent reply	other threads:[~2020-04-22 16:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22 10:28 [PATCH iproute2 v2 0/2] bpf: memory access fixes Jamal Hadi Salim
2020-04-22 10:28 ` [PATCH iproute2 v2 1/2] bpf: Fix segfault when custom pinning is used Jamal Hadi Salim
2020-04-22 12:24   ` Andrea Claudi
2020-04-22 14:43     ` Dominique Martinet
2020-04-22 17:07       ` Jamal Hadi Salim
2020-04-22 16:35   ` Stephen Hemminger [this message]
2020-04-22 17:19     ` Jamal Hadi Salim
2020-04-23  6:30       ` Dominique Martinet
2020-04-23 17:46         ` Jamal Hadi Salim
2020-04-22 10:28 ` [PATCH iproute2 v2 2/2] bpf: Fix mem leak and extraneous free() in error path Jamal Hadi Salim
2020-04-22 14:44   ` Dominique Martinet
2020-04-30  5:40 ` [PATCH iproute2 v2 0/2] bpf: memory access fixes Stephen Hemminger

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=20200422093531.4d9364c9@hermes.lan \
    --to=stephen@networkplumber$(echo .)org \
    --cc=aclaudi@redhat$(echo .)com \
    --cc=asmadeus@codewreck$(echo .)org \
    --cc=daniel@iogearbox$(echo .)net \
    --cc=dsahern@gmail$(echo .)com \
    --cc=hadi@mojatatu$(echo .)com \
    --cc=jhs@mojatatu$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox