Skip to content

Commit

Permalink
Fix reading buffer overflow in parse_string
Browse files Browse the repository at this point in the history
  • Loading branch information
FSMaxB committed May 10, 2017
1 parent b537ca7 commit a167d9e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu
/* calculate approximate size of the output (overestimate) */
size_t allocation_length = 0;
size_t skipped_bytes = 0;
while ((*input_end != '\"') && ((size_t)(input_end - input_buffer->content) < input_buffer->length))
while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"'))
{
/* is escape sequence */
if (input_end[0] == '\\')
Expand All @@ -672,7 +672,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu
}
input_end++;
}
if (*input_end != '\"')
if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"'))
{
goto fail; /* string ended unexpectedly */
}
Expand Down

0 comments on commit a167d9e

Please sign in to comment.