1
0
mirror of https://github.com/DaveGamble/cJSON synced 2024-12-22 06:40:04 +00:00

Fix a null pointer crash in cJSON_ReplaceItemViaPointer (#726)

If the parent passed in cJSON_ReplaceItemViaPointer has not a child, which means parent->child is null, a null pointer dereference crash will be happened inside cJSON_ReplaceItemViaPointer.

This commit adds the NULL check of `parent->child` beforehand to inform user such incorrect usage.

Signed-off-by: hopper-vul <hopper.vul@gmail.com>
This commit is contained in:
hopper-vul 2023-07-01 16:18:32 +08:00 committed by GitHub
parent b45f48e600
commit 766dd9d590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2291,7 +2291,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
{
if ((parent == NULL) || (replacement == NULL) || (item == NULL))
if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
{
return false;
}