json: Add checks when skipping byte

* src/cJSON.c (parse_string, cJSON_Minify): Check for
terminating NULL byte when skipping the byte after a an escaped
quote.
This commit is contained in:
Andre Heinecke 2018-08-08 13:30:01 +02:00
parent 6e48bb0f1c
commit 974a95db04
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -249,7 +249,7 @@ parse_string (cJSON * item, const char *str, const char **ep)
} /* not a string! */ } /* not a string! */
while (*ptr != '\"' && *ptr && ++len) while (*ptr != '\"' && *ptr && ++len)
if (*ptr++ == '\\') if (*ptr++ == '\\' && *ptr)
ptr++; /* Skip escaped quotes. */ ptr++; /* Skip escaped quotes. */
out = xtrymalloc (len + 2); /* This is how long we need for the out = xtrymalloc (len + 2); /* This is how long we need for the
@ -268,6 +268,8 @@ parse_string (cJSON * item, const char *str, const char **ep)
else else
{ {
ptr++; ptr++;
if (!*ptr)
break;
switch (*ptr) switch (*ptr)
{ {
case 'b': case 'b':
@ -1416,9 +1418,11 @@ cJSON_Minify (char *json)
{ {
if (*json == '\\') if (*json == '\\')
*into++ = *json++; *into++ = *json++;
*into++ = *json++; if (*json)
*into++ = *json++;
} }
*into++ = *json++; if (*json)
*into++ = *json++;
} /* String literals, which are \" sensitive. */ } /* String literals, which are \" sensitive. */
else else
*into++ = *json++; /* All other characters. */ *into++ = *json++; /* All other characters. */