netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamal Hadi Salim <jhs@mojatatu.com>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org, dsahern@gmail.com, aclaudi@redhat.com,
	daniel@iogearbox.net, asmadeus@codewreck.org,
	Jamal Hadi Salim <hadi@mojatatu.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>
Subject: [PATCH iproute2 v2 1/2] bpf: Fix segfault when custom pinning is used
Date: Wed, 22 Apr 2020 06:28:07 -0400	[thread overview]
Message-ID: <20200422102808.9197-2-jhs@emojatatu.com> (raw)
In-Reply-To: <20200422102808.9197-1-jhs@emojatatu.com>

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

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] = {};
 	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));
 	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;
 }
 
-- 
2.20.1


  reply	other threads:[~2020-04-22 10:31 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 ` Jamal Hadi Salim [this message]
2020-04-22 12:24   ` [PATCH iproute2 v2 1/2] bpf: Fix segfault when custom pinning is used Andrea Claudi
2020-04-22 14:43     ` Dominique Martinet
2020-04-22 17:07       ` Jamal Hadi Salim
2020-04-22 16:35   ` Stephen Hemminger
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=20200422102808.9197-2-jhs@emojatatu.com \
    --to=jhs@mojatatu.com \
    --cc=aclaudi@redhat.com \
    --cc=asmadeus@codewreck.org \
    --cc=daniel@iogearbox.net \
    --cc=dsahern@gmail.com \
    --cc=hadi@mojatatu.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).