From 3f64defe13b4a8712f95de009fc1f8b09e2bf779 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 3 Aug 2023 10:35:56 -0400 Subject: [PATCH] [ruby/yarp] Make sure lexing ? does not read off the end https://github.com/ruby/yarp/commit/d694e3ebf2 --- yarp/yarp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yarp/yarp.c b/yarp/yarp.c index 2573663f26..dd27c172f4 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -5307,11 +5307,15 @@ lex_question_mark(yp_parser_t *parser) { return YP_TOKEN_CHARACTER_LITERAL; } else { size_t encoding_width = parser->encoding.char_width(parser->current.end); + // We only want to return a character literal if there's exactly one // alphanumeric character right after the `?` if ( !parser->encoding.alnum_char(parser->current.end) || - !parser->encoding.alnum_char(parser->current.end + encoding_width) + ( + (parser->current.end + encoding_width >= parser->end) || + !parser->encoding.alnum_char(parser->current.end + encoding_width) + ) ) { lex_state_set(parser, YP_LEX_STATE_END); parser->current.end += encoding_width;