Skip to content

Conversation

@lxyjy6
Copy link

@lxyjy6 lxyjy6 commented Oct 22, 2025

A heap-use-after-free error occurs in the test case below when trying to replace an item in a JSON object with a cJSON item that has already been freed. The ASan report clearly shows that we're attempting to read from memory that was previously freed.

The function should validate the newitem parameter before using it.

Test Case:
TEST_F(cJSONReplaceItemTest, UseAfterFree) {
cJSON* temp_item = cJSON_CreateString("temp");
cJSON_Delete(temp_item);
EXPECT_FALSE(cJSON_ReplaceItemInObjectCaseSensitive(root, "key", temp_item));
}

@lxyjy6 lxyjy6 changed the title add null pointer check in cJSON_ReplaceItemInObjectCaseSensitive Add null pointer check in cJSON_ReplaceItemInObjectCaseSensitive Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant