From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 2/3] batctl: version: avoid use of uninitialized read buffer
Date: Sun, 05 Jul 2026 14:55:07 +0200 [thread overview]
Message-ID: <20260705-bugfixes-version-v1-2-5f02046c7eea@narfation.org> (raw)
In-Reply-To: <20260705-bugfixes-version-v1-0-5f02046c7eea@narfation.org>
version() strips the trailing newline from line_ptr before checking whether
read_file() actually succeeded. If the read_file() returned an error, it
could be that line_ptr was allocated buyt not yet initialized. It could
therefore not contain any \0 delimiter - making the strlen read outside the
buffer. The write of the \0 could therefore also be outside the buffer.
Only attempt to access the buffer when a success was indicated.
Fixes: dbc4a8c8e585 ("batctl: version also prints the kernel module version if available")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
main.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/main.c b/main.c
index 79ed4ef..e625291 100644
--- a/main.c
+++ b/main.c
@@ -132,13 +132,14 @@ static void version(void)
printf("batctl %s [batman-adv: ", SOURCE_VERSION);
ret = read_file(module_ver_path, USE_READ_BUFF | SILENCE_ERRORS);
- if ((line_ptr) && (line_ptr[strlen(line_ptr) - 1] == '\n'))
- line_ptr[strlen(line_ptr) - 1] = '\0';
+ if (ret == EXIT_SUCCESS) {
+ if (line_ptr[strlen(line_ptr) - 1] == '\n')
+ line_ptr[strlen(line_ptr) - 1] = '\0';
- if (ret == EXIT_SUCCESS)
printf("%s]\n", line_ptr);
- else
+ } else {
printf("module version unknown]\n");
+ }
free(line_ptr);
exit(EXIT_SUCCESS);
--
2.47.3
next prev parent reply other threads:[~2026-07-05 12:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 12:55 [PATCH 0/3] batctl: version bugfixes Sven Eckelmann
2026-07-05 12:55 ` [PATCH 1/3] batctl: only mark file read successful on read line Sven Eckelmann
2026-07-05 12:55 ` Sven Eckelmann [this message]
2026-07-05 12:55 ` [PATCH 3/3] batctl: version: don't strip newline for empty buffer Sven Eckelmann
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=20260705-bugfixes-version-v1-2-5f02046c7eea@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.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.