cJSON_Raw: Additional checks in print_value

This commit is contained in:
Max Bruckner 2017-01-05 21:30:37 +01:00
parent 9ef44fc0b6
commit ddadb44a67

18
cJSON.c
View File

@ -990,12 +990,26 @@ static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *
out = print_number(item, p); out = print_number(item, p);
break; break;
case cJSON_Raw: case cJSON_Raw:
out = ensure(p, strlen(item->valuestring)); {
size_t raw_length = 0;
if (item->valuestring == NULL)
{
if (!p->noalloc)
{
cJSON_free(p->buffer);
}
out = NULL;
break;
}
raw_length = strlen(item->valuestring) + sizeof('\0');
out = ensure(p, raw_length);
if (out) if (out)
{ {
strcpy(out, item->valuestring); memcpy(out, item->valuestring, raw_length);
} }
break; break;
}
case cJSON_String: case cJSON_String:
out = print_string(item, p); out = print_string(item, p);
break; break;