Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cJSON_AddItemToObject() causes segmentation fault if id == NULL #182

Closed
tranzistoren opened this issue Jun 27, 2017 · 2 comments
Closed
Labels

Comments

@tranzistoren
Copy link

tranzistoren commented Jun 27, 2017

First, the function:

cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
{
    cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string, &global_hooks), item)
    item->type &= ~cJSON_StringIsConst;
}

In cJSON_AddItemToObjectCS we see:

if (!item)
{
    return;
}

So that would be fine, but then, cJSON_AddItemToObject references a field from item, which, as we know, is a NULL.

@FSMaxB FSMaxB added the bug label Jun 27, 2017
@FSMaxB
Copy link
Collaborator

FSMaxB commented Jun 27, 2017

Yes, cJSON_AddItemToObject should also check if the item is a NULL pointer.

@FSMaxB FSMaxB mentioned this issue Jun 27, 2017
4 tasks
@FSMaxB
Copy link
Collaborator

FSMaxB commented Jun 28, 2017

Fixed in version 1.5.6

@FSMaxB FSMaxB closed this as completed Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants