Skip to content

Commit 178862e

Browse files
committed
fix: string escape char "\" at the end of a file
Previously this resulted in invalid memory access. Found by the fuzzer.
1 parent c781c9f commit 178862e

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
@@ -7224,6 +7224,12 @@ parser_lex(yp_parser_t *parser) {
72247224
breakpoint = yp_strpbrk(parser, breakpoint + 1, breakpoints, parser->end - (breakpoint + 1));
72257225
break;
72267226
case '\\': {
7227+
// Check that we're not at the end of the file.
7228+
if (breakpoint + 1 >= parser->end) {
7229+
breakpoint = NULL;
7230+
break;
7231+
}
7232+
72277233
// If we hit escapes, then we need to treat the next token
72287234
// literally. In this case we'll skip past the next character and
72297235
// find the next breakpoint.

test/yarp/fuzzer_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ def snippet(name, source)
1414

1515
snippet "incomplete global variable", "$"
1616
snippet "incomplete symbol", ":"
17+
snippet "incomplete escaped string", '"\\'
1718
end

0 commit comments

Comments
 (0)