Skip to content

Commit b248553

Browse files
committed
fix: comment followed by whitespace at end of file
Previously this resulted in invalid memory access. Found by the fuzzer.
1 parent ec4abd8 commit b248553

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/yarp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5921,7 +5921,7 @@ parser_lex(yp_parser_t *parser) {
59215921

59225922
// If this is not followed by a comment, then we can break out
59235923
// of this loop.
5924-
if (*following != '#') break;
5924+
if (peek_at(parser, following) != '#') break;
59255925

59265926
// If there is a comment, then we need to find the end of the
59275927
// comment and continue searching from there.

test/yarp/fuzzer_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def snippet(name, source)
1616
snippet "incomplete symbol", ":"
1717
snippet "incomplete escaped string", '"\\'
1818
snippet "trailing comment", "1\n#\n"
19+
snippet "comment followed by whitespace at end of file", "1\n#\n "
1920
snippet "trailing asterisk", "a *"
2021
snippet "incomplete decimal number", "0d"
2122
snippet "incomplete binary number", "0b"

0 commit comments

Comments
 (0)