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 authored and Alan Wang committed 2024-04-26 16:34:05 +08:00
1 parent 87d8f0961a
commit 7e4d5dabe7
1 file changed
+1 -1
+1 -1
View File
@@ -406,7 +406,7 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
return NULL; return NULL;
} }
/* return NULL if the object is corrupted */ /* return NULL if the object is corrupted */
if (object->valuestring == NULL) if (object->valuestring == NULL || valuestring == NULL)
{ {
return NULL; return NULL;
} }