Commit 73f6e67
committed
conf: fix one-byte OOB read/write underflow in chomp()
chomp() trims trailing newlines from a line read from a .service
config file. For a string consisting of only a newline (str ==
n, exactly what fgets() produces for a blank line), the pointer
p starts at str+0. The loop body zeroes str[0], decrements p to
str-1, and then unconditionally dereferences *p to test the loop
condition -- a one-byte read before the start of the buffer. If
that stray byte also happens to be 0x0A the loop keeps walking
backward, turning the OOB read into an OOB write as well.
Confirmed with the project's own asan CI flags
(-fsanitize=address,undefined -fno-sanitize-recover=undefined):
a .service file with a blank line between two directives makes
UBSan report 'load of address ... with insufficient space for an
object of type char' at this exact line, reachable via the normal
parse() -> read_line() -> chomp() path.
Bound the pointer before dereferencing it, mirroring the tab
indentation used by the rest of the function (the line was
previously indented with spaces instead of a tab).
Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>1 parent e190ef7 commit 73f6e67
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
0 commit comments