Skip to content

A null pointer crash in cJSON_ReplaceItemViaPointer #725

@hopper-vul

Description

@hopper-vul

Hi,
when fuzzing cJSON, we found a null pointer crash happened in cJSON_ReplaceItemViaPointer.

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 at the following statements:

CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
        ...
      if (replacement->next == NULL)
      {
          parent->child->prev = replacement;
      }

As detaching an item from an empty object is an undesirable behavior, instead of raising an uneasy core dump, maybe we can check it beforehand and inform the incorrect usage early to user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions