[ruby/yarp] fix: trailing asterisk at end of file

Previously this resulted in invalid memory access.

Found by the fuzzer.

https://github.com/ruby/yarp/commit/c86b4907b4
This commit is contained in:
Mike Dalessio 2023-08-29 22:30:12 -04:00 committed by git
parent bd0268372e
commit c83552a596
2 changed files with 4 additions and 0 deletions

View File

@ -16,4 +16,5 @@ class FuzzerTest < Test::Unit::TestCase
snippet "incomplete symbol", ":"
snippet "incomplete escaped string", '"\\'
snippet "trailing comment", "1\n#\n"
snippet "trailing asterisk", "a *"
end

View File

@ -380,6 +380,9 @@ lex_state_arg_p(yp_parser_t *parser) {
static inline bool
lex_state_spcarg_p(yp_parser_t *parser, bool space_seen) {
if (parser->current.end >= parser->end) {
return false;
}
return lex_state_arg_p(parser) && space_seen && !yp_char_is_whitespace(*parser->current.end);
}