From: Mohammad abu saleh <ml.abusaleh.ml@gmail.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org,
Mohammad abu saleh <ml.abusaleh.ml@gmail.com>
Subject: [PATCH iproute2] lib: fix memory leak in getcmdline()
Date: Thu, 1 Oct 2026 04:31:29 +0200 [thread overview]
Message-ID: <20261001023129.290059-1-ml.abusaleh.ml@gmail.com> (raw)
getline() may allocate line1 even when it returns -1, and the caller
must free the buffer on the error path.
When batch input ends with a missing continuation line, getcmdline()
returns without freeing line1. This can be reproduced with:
printf 'link show \\\n' | ./ip/ip -batch -
Free line1 before returning. Valgrind reports 120 bytes definitely
lost before this change.
Fixes: c2f3a0f94de9 ("Fix batch mode, allow continuation, comments, etc.")
Signed-off-by: Mohammad abu saleh <ml.abusaleh.ml@gmail.com>
---
lib/utils.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/utils.c b/lib/utils.c
index 50602e59..6388d981 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1372,6 +1372,7 @@ static ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
cc1 = getline(&line1, &len1, in);
if (cc1 < 0) {
fprintf(stderr, "Missing continuation line\n");
+ free(line1);
return cc1;
}
--
2.53.0
next reply other threads:[~2026-10-01 2:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 2:31 Mohammad abu saleh [this message]
2026-10-02 16:00 ` [PATCH iproute2] lib: fix memory leak in getcmdline() patchwork-bot+netdevbpf
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=20261001023129.290059-1-ml.abusaleh.ml@gmail.com \
--to=ml.abusaleh.ml@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox