From 95e29b0423450447ea0adbf06564969f0e437673 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 21 Aug 2023 14:47:24 -0400 Subject: [PATCH] [ruby/yarp] fix: avoid invalid memory read when CR is present without LF https://github.com/ruby/yarp/commit/2296c037de --- yarp/yarp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yarp/yarp.c b/yarp/yarp.c index 65c9e959fd..3f250abfe4 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -6183,7 +6183,9 @@ parser_lex(yp_parser_t *parser) { parser->current.end++; } - yp_newline_list_check_append(&parser->newline_list, parser->current.end); + if (peek(parser) == '\n') { + yp_newline_list_append(&parser->newline_list, parser->current.end); + } parser->current.end++; if (parser->current.end < parser->end) { @@ -6191,7 +6193,7 @@ parser_lex(yp_parser_t *parser) { } } - switch (*parser->current.end) { + switch (peek(parser)) { case 'i': { parser->current.end++;