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:
parent
6e48bb0f1c
commit
974a95db04
10
src/cJSON.c
10
src/cJSON.c
@ -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. */
|
||||||
|
Loading…
Reference in New Issue
Block a user