Skip to content

Commit

Permalink
Merge pull request #118 from mjerris/parser
Browse files Browse the repository at this point in the history
prevent read beyond end of buffer when string ends with malformed utf
  • Loading branch information
FSMaxB authored Feb 26, 2017
2 parents 4fce9cc + 72e6e23 commit 29f312d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,16 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi
unsigned char utf8_length = 0;
unsigned char sequence_length = 0;

/* get the first utf16 sequence */
first_code = parse_hex4(first_sequence + 2);
if ((input_end - first_sequence) < 6)
{
/* input ends unexpectedly */
*error_pointer = first_sequence;
goto fail;
}

/* get the first utf16 sequence */
first_code = parse_hex4(first_sequence + 2);

/* check that the code is valid */
if (((first_code >= 0xDC00) && (first_code <= 0xDFFF)) || (first_code == 0))
{
Expand Down

0 comments on commit 29f312d

Please sign in to comment.