Skip to content

Commit

Permalink
Add NULL check to cJSON_SetValuestring()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Up-wind authored and Alanscut committed Apr 26, 2024
1 parent 87d8f09 commit 7e4d5da
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7e4d5da

Please sign in to comment.