fix: add allocate check for replace_item_in_object (#675)

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
This commit is contained in:
Junbo Zheng 2022-03-29 15:02:59 +08:00 committed by GitHub
parent a6424b85dd
commit b45f48e600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2361,6 +2361,11 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO
cJSON_free(replacement->string); cJSON_free(replacement->string);
} }
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
if (replacement->string == NULL)
{
return false;
}
replacement->type &= ~cJSON_StringIsConst; replacement->type &= ~cJSON_StringIsConst;
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);