Skip to content

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

Closed
@tranzistoren

Description

@tranzistoren

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.

Activity

FSMaxB

FSMaxB commented on Jun 27, 2017

@FSMaxB
Collaborator

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

FSMaxB

FSMaxB commented on Jun 28, 2017

@FSMaxB
Collaborator

Fixed in version 1.5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @tranzistoren@FSMaxB

      Issue actions

        cJSON_AddItemToObject() causes segmentation fault if id == NULL · Issue #182 · DaveGamble/cJSON