Skip to content

Commit

Permalink
Fix out of bounds memory access bug in split_by_ascii_whitespace()
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 23, 2023
1 parent ca81368 commit 74ba02f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/ascii.jou
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def split_by_ascii_whitespace(s: byte*) -> byte**:
break
*result_ptr++ = s

while not is_ascii_whitespace(*s):
while *s != '\0' and not is_ascii_whitespace(*s):
s++

if *s == '\0':
Expand Down
11 changes: 11 additions & 0 deletions tests/should_succeed/ascii_test.jou
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ def main() -> int:
puts(words[i])
free(words)

s = ""
words = split_by_ascii_whitespace(s)
assert words[0] == NULL
free(words)

s = "test1 test2"
words = split_by_ascii_whitespace(s)
printf("%s %s\n", words[0], words[1]) # Output: test1 test2
assert words[2] == NULL
free(words)

return 0

0 comments on commit 74ba02f

Please sign in to comment.