Add NULL check to cJSON_SetValuestring()

If the valuestring passed to cJSON_SetValuestring is NULL, a null pointer dereference will happen.

This commit adds the NULL check of valuestring before it is dereferenced.
This commit is contained in:
Up-wind
2024-03-25 20:07:11 +08:00
committed by Alan Wang
parent 87d8f0961a
commit 7e4d5dabe7

View File

@@ -406,7 +406,7 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
return NULL;
}
/* return NULL if the object is corrupted */
if (object->valuestring == NULL)
if (object->valuestring == NULL || valuestring == NULL)
{
return NULL;
}