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 1/3] batctl: only mark file read successful on read line
Date: Sun, 05 Jul 2026 14:55:06 +0200 [thread overview]
Message-ID: <20260705-bugfixes-version-v1-1-5f02046c7eea@narfation.org> (raw)
In-Reply-To: <20260705-bugfixes-version-v1-0-5f02046c7eea@narfation.org>
The line_ptr is shared globally. It can happen that another function like
parse_hosts_file() allocated the buffer successfully. But the next
getline() in read_file() fails - but keeps the line_ptr valid. In this
case, the function would return a success - even when the buffer contains
stale data.
Instead only set the return value to EXIT_SUCCESS when a single line could
be read.
Fixes: deb324e65044 ("batctl: buffer based reading replaced by line-by-line reading")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
functions.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/functions.c b/functions.c
index 00dbd3d..349569d 100644
--- a/functions.c
+++ b/functions.c
@@ -147,6 +147,8 @@ int read_file(const char *full_path, int read_opt)
}
while (getline(&line_ptr, &len, fp) != -1) {
+ res = EXIT_SUCCESS;
+
/* the buffer will be handled elsewhere */
if (read_opt & USE_READ_BUFF)
break;
@@ -154,9 +156,6 @@ int read_file(const char *full_path, int read_opt)
printf("%s", line_ptr);
}
- if (line_ptr)
- res = EXIT_SUCCESS;
-
fclose(fp);
return res;
}
--
2.47.3
next prev parent reply other threads:[~2026-07-05 12:56 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 ` Sven Eckelmann [this message]
2026-07-05 12:55 ` [PATCH 2/3] batctl: version: avoid use of uninitialized read buffer Sven Eckelmann
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-1-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.