Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d3117fc

Browse files
committed
Fix out-of-bounds read in json_lex_string
Commit 3838fa2 added a lookahead loop to allow building strings multiple bytes at a time. This loop could exit because it reached the end of input, yet did not check for that before checking if we reached the end of a valid string. To fix, put the end of string check back in the outer loop. Per Valgrind animal skink
1 parent 3b00a94 commit d3117fc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/common/jsonapi.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ json_lex_string(JsonLexContext *lex)
686686
lex->token_terminator = s;
687687
return JSON_INVALID_TOKEN;
688688
}
689+
else if (*s == '"')
690+
break;
689691
else if (*s == '\\')
690692
{
691693
/* OK, we have an escape character. */
@@ -870,21 +872,21 @@ json_lex_string(JsonLexContext *lex)
870872
if (lex->strval != NULL)
871873
appendBinaryStringInfo(lex->strval, s, p - s);
872874

873-
if (*p == '"')
874-
{
875-
/* Hooray, we found the end of the string! */
876-
lex->prev_token_terminator = lex->token_terminator;
877-
lex->token_terminator = p + 1;
878-
return JSON_SUCCESS;
879-
}
880-
881875
/*
882876
* s will be incremented at the top of the loop, so set it to just
883877
* behind our lookahead position
884878
*/
885879
s = p - 1;
886880
}
887881
}
882+
883+
if (hi_surrogate != -1)
884+
return JSON_UNICODE_LOW_SURROGATE;
885+
886+
/* Hooray, we found the end of the string! */
887+
lex->prev_token_terminator = lex->token_terminator;
888+
lex->token_terminator = s + 1;
889+
return JSON_SUCCESS;
888890
}
889891

890892
/*

0 commit comments

Comments
 (0)