[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200423175857.20180-3-jhs@emojatatu.com>
Date: Thu, 23 Apr 2020 13:58:57 -0400
From: Jamal Hadi Salim <jhs@...atatu.com>
To: stephen@...workplumber.org
Cc: netdev@...r.kernel.org, dsahern@...il.com, aclaudi@...hat.com,
daniel@...earbox.net, asmadeus@...ewreck.org,
Jamal Hadi Salim <jhs@...atatu.com>
Subject: [PATCH iproute2 v3 2/2] bpf: Fix mem leak and extraneous free() in error path
From: Jamal Hadi Salim <jhs@...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 | 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
Powered by blists - more mailing lists