Skip to content

Commit 78ed75e

Browse files
committed
fix: incomplete escape in list at the end of file
Previously this resulted in invalid memory access. Found by the fuzzer.
1 parent af5b85a commit 78ed75e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/yarp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6952,6 +6952,12 @@ parser_lex(yp_parser_t *parser) {
69526952
// literally. In this case we'll skip past the next character
69536953
// and find the next breakpoint.
69546954
if (*breakpoint == '\\') {
6955+
// Check that we're not at the end of the file.
6956+
if (breakpoint + 1 >= parser->end) {
6957+
breakpoint = NULL;
6958+
continue;
6959+
}
6960+
69556961
yp_unescape_type_t unescape_type = lex_mode->as.list.interpolation ? YP_UNESCAPE_ALL : YP_UNESCAPE_MINIMAL;
69566962
size_t difference = yp_unescape_calculate_difference(parser, breakpoint, unescape_type, false);
69576963

test/yarp/fuzzer_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ def snippet(name, source)
2121
snippet "incomplete binary number", "0b"
2222
snippet "incomplete octal number", "0o"
2323
snippet "incomplete hex number", "0x"
24+
snippet "incomplete escaped list", "%w[\\"
2425
end

0 commit comments

Comments
 (0)