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 3/3] batctl: version: don't strip newline for empty buffer
Date: Sun, 05 Jul 2026 14:55:08 +0200 [thread overview]
Message-ID: <20260705-bugfixes-version-v1-3-5f02046c7eea@narfation.org> (raw)
In-Reply-To: <20260705-bugfixes-version-v1-0-5f02046c7eea@narfation.org>
When read_file() would return an empty buffer, then version() must not
strip the last byte. Otherwise it would try to access 1 byte before the
start of the buffer.
Fixes: dbc4a8c8e585 ("batctl: version also prints the kernel module version if available")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
main.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/main.c b/main.c
index e625291..0cf99d7 100644
--- a/main.c
+++ b/main.c
@@ -133,8 +133,10 @@ static void version(void)
ret = read_file(module_ver_path, USE_READ_BUFF | SILENCE_ERRORS);
if (ret == EXIT_SUCCESS) {
- if (line_ptr[strlen(line_ptr) - 1] == '\n')
- line_ptr[strlen(line_ptr) - 1] = '\0';
+ size_t line_len = strlen(line_ptr);
+
+ if (line_len > 0 && line_ptr[line_len - 1] == '\n')
+ line_ptr[line_len - 1] = '\0';
printf("%s]\n", line_ptr);
} else {
--
2.47.3
prev parent reply other threads:[~2026-07-05 12:58 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 ` [PATCH 2/3] batctl: version: avoid use of uninitialized read buffer Sven Eckelmann
2026-07-05 12:55 ` Sven Eckelmann [this message]
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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox