mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 00:24:51 +00:00
print_lines: fix bugs in line length calculation
1) The loop for determining the line length read from a character offset before checking whether the offset is smaller than the given string length. This could have caused access outside the string buffer. 2) The routine for determining the line length first seeked for the offset of the last real character of the line and than added one for getting the length but only if the following character was '\n'. This has to be done for any other line-terminating character too. The only case where you don't want to do this is when the end of the whole string is reached. Issue #2967
This commit is contained in:
parent
9a2af89c4e
commit
cc4a72243d
@ -69,12 +69,14 @@ void Genode::print_lines(char const *string, size_t len, FUNC const &func)
|
||||
size_t const line_len =
|
||||
({
|
||||
size_t i = 0;
|
||||
for (; string[i] && i < len && string[i] != '\n'; i++);
|
||||
|
||||
/* the newline character belongs to the line */
|
||||
if (string[i] == '\n')
|
||||
i++;
|
||||
for (; i < len; i++) {
|
||||
if (string[i] == '\0' || string[i] == '\n') {
|
||||
|
||||
/* the line length is the offset of the last real character + 1 */
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
i;
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user