From e6a2cf9fd79330bd6838cb504648a874f30f5629 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 11 Mar 2025 18:49:14 +0100 Subject: [PATCH] [ruby/json] Fix potential out of bound read in `json_string_unescape`. https://github.com/ruby/json/commit/cf242d89a0 --- ext/json/parser/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index 0a1d937575..d990612a2b 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -608,7 +608,7 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c buffer = RSTRING_PTR(result); bufferStart = buffer; - while ((pe = memchr(pe, '\\', stringEnd - pe))) { + while (pe < stringEnd && (pe = memchr(pe, '\\', stringEnd - pe))) { unescape = (char *) "?"; unescape_len = 1; if (pe > p) {