[ruby/yarp] fix: heredoc with incomplete escape at end of file

Previously this resulted in invalid memory access.

Found by the fuzzer.

https://github.com/ruby/yarp/commit/ec4abd87f4
This commit is contained in:
Mike Dalessio 2023-08-30 13:52:03 -04:00 committed by git
parent 341f47a6dd
commit ae7f907559
2 changed files with 7 additions and 0 deletions

View File

@ -23,4 +23,5 @@ class FuzzerTest < Test::Unit::TestCase
snippet "incomplete hex number", "0x"
snippet "incomplete escaped list", "%w[\\"
snippet "incomplete escaped regex", "/a\\"
snippet "unterminated heredoc with unterminated escape at end of file", "<<A\n\\"
end

View File

@ -7413,6 +7413,12 @@ parser_lex(yp_parser_t *parser) {
break;
}
case '\\': {
// Check that we're not at the end of the file.
if (breakpoint + 1 >= parser->end) {
breakpoint = NULL;
break;
}
// If we hit an escape, then we need to skip past
// however many characters the escape takes up. However
// it's important that if \n or \r\n are escaped that we