From 2d009805e71e76c4f7678409aea804e18df01446 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 30 Aug 2023 14:03:03 -0400 Subject: [PATCH] [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 --- test/yarp/fuzzer_test.rb | 1 + yarp/yarp.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/yarp/fuzzer_test.rb b/test/yarp/fuzzer_test.rb index 6dfbf94f39..8d818897a6 100644 --- a/test/yarp/fuzzer_test.rb +++ b/test/yarp/fuzzer_test.rb @@ -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" diff --git a/yarp/yarp.c b/yarp/yarp.c index 37d55cd467..2422fb4571 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -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.