diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-08-03 10:35:56 -0400 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-08-16 17:47:32 -0700 |
| commit | 3f64defe13b4a8712f95de009fc1f8b09e2bf779 (patch) | |
| tree | 87c8862a79b2db0c88cb6a3c95c8628a7bb8c259 | |
| parent | d2eb82d9692c0ad2da36e5b910dd34c77395733a (diff) | |
[ruby/yarp] Make sure lexing ? does not read off the end
https://github.com/ruby/yarp/commit/d694e3ebf2
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8226
| -rw-r--r-- | yarp/yarp.c | 6 |
1 files changed, 5 insertions, 1 deletions
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; |
