[PATCH 27/28] batctl: bisect_iv: avoid out of bound access on short lines
Sven Eckelmann <[email protected]> Sun, 21 Jun 2026 16:24:17 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
The parse_log_file assumes that it can jump over the first 13 characters
without checking if the line is actually 13 bytes long. A short log line
would therefore cause a jump outside of the initialized buffer area.
To avoid this, ignore all files smaller than 14 bytes.
Fixes: ece05e1c4c1f ("[batctl] bisect (a tool to analyze logfiles) added")
Signed-off-by: Sven Eckelmann <[email protected]>
---
bisect_iv.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/bisect_iv.c b/bisect_iv.c
index 4420be9..6c3f5d6 100644
--- a/bisect_iv.c
+++ b/bisect_iv.c
@@ -501,10 +501,14 @@ static int parse_log_file(char *file_path)
}
while (fgets(line_buff, sizeof(line_buff), fd)) {
- /* ignore the timestamp at the beginning of each line */
- start_ptr = line_buff + 13;
line_count++;
+ /* ignore the timestamp at the beginning of each line */
+ if (strlen(line_buff) <= 13)
+ continue;
+
+ start_ptr = line_buff + 13;
+
if (strstr(start_ptr, "Received BATMAN packet via NB")) {
strtok_r(start_ptr, " ", &start_ptr_safe);
neigh = NULL;
--
2.47.3