From b4ace2f3443e6746a54eb14c7f50aa719540181c Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Thu, 1 Feb 2024 09:19:01 +0100 Subject: libq/contents: fix invalid access problem pointed out by valgrind len represents the entire string length, but we start scanning after the line identifier, so substract that size from len, such that we don't start scanning after the end of the input string. Signed-off-by: Fabian Groffen --- libq/contents.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libq/contents.c b/libq/contents.c index feb1c0b..6ec4491 100644 --- a/libq/contents.c +++ b/libq/contents.c @@ -34,6 +34,9 @@ contents_parse_line_len(char *line, size_t len) len--; } + if (len <= 4) /* minimal: "dir /" */ + return NULL; + memset(&e, 0x00, sizeof(e)); e._data = line; @@ -47,6 +50,7 @@ contents_parse_line_len(char *line, size_t len) return NULL; e.name = e._data + 4; + len -= 4; switch (e.type) { /* dir /bin */ -- cgit v1.2.3-65-gdbad