All of lore.kernel.org
 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 <jhs@mojatatu.com>
Subject: [PATCH iproute2 v3 2/2] bpf: Fix mem leak and extraneous free() in error path
Date: Thu, 23 Apr 2020 13:58:57 -0400	[thread overview]
Message-ID: <20200423175857.20180-3-jhs@emojatatu.com> (raw)
In-Reply-To: <20200423175857.20180-1-jhs@emojatatu.com>

From: Jamal Hadi Salim <jhs@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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/bpf.c b/lib/bpf.c
index 73f3a590..b05c8568 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -1519,13 +1519,15 @@ static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx,
 	ret = asprintf(&rem, "%s/", todo);
 	if (ret < 0) {
 		fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
-		goto out;
+		return ret;
 	}
 
 	sub = strtok(rem, "/");
 	while (sub) {
-		if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX)
-			return -EINVAL;
+		if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX) {
+			errno = EINVAL;
+			goto out;
+		}
 
 		strcat(tmp, sub);
 		strcat(tmp, "/");
-- 
2.20.1


  parent reply	other threads:[~2020-04-23 17:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 17:58 [PATCH iproute2 v3 0/2] bpf: memory access fixes Jamal Hadi Salim
2020-04-23 17:58 ` [PATCH iproute2 v3 1/2] bpf: Fix segfault when custom pinning is used Jamal Hadi Salim
2020-04-23 17:58 ` Jamal Hadi Salim [this message]
2020-04-24 16:58 ` [PATCH iproute2 v3 0/2] bpf: memory access fixes Andrea Claudi
2020-04-28 16:15 ` Jamal Hadi Salim
2020-05-18 13:00   ` Jamal Hadi Salim
2020-05-23  1:33     ` Daniel Borkmann
2020-05-23 10:32       ` Jamal Hadi Salim
2020-05-25  8:53         ` Andrea Claudi
2020-05-26 12:27           ` Jamal Hadi Salim

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=20200423175857.20180-3-jhs@emojatatu.com \
    --to=jhs@mojatatu.com \
    --cc=aclaudi@redhat.com \
    --cc=asmadeus@codewreck.org \
    --cc=daniel@iogearbox.net \
    --cc=dsahern@gmail.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 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.