[ruby/yarp] fix: comment followed by whitespace at end of file

Previously this resulted in invalid memory access.

Found by the fuzzer.

https://github.com/ruby/yarp/commit/b248553dd6
This commit is contained in:
Mike Dalessio 2023-08-30 14:03:03 -04:00 committed by git
parent ae7f907559
commit 2d009805e7
2 changed files with 2 additions and 1 deletions

View File

@ -16,6 +16,7 @@ class FuzzerTest < Test::Unit::TestCase
snippet "incomplete symbol", ":"
snippet "incomplete escaped string", '"\\'
snippet "trailing comment", "1\n#\n"
snippet "comment followed by whitespace at end of file", "1\n#\n "
snippet "trailing asterisk", "a *"
snippet "incomplete decimal number", "0d"
snippet "incomplete binary number", "0b"

View File

@ -5921,7 +5921,7 @@ parser_lex(yp_parser_t *parser) {
// If this is not followed by a comment, then we can break out
// of this loop.
if (*following != '#') break;
if (peek_at(parser, following) != '#') break;
// If there is a comment, then we need to find the end of the
// comment and continue searching from there.