Skip to content

cJSON_Utils: respect item ownership when a JSON Patch targets the root - #1127

Open
gsmarcil wants to merge 1 commit into
DaveGamble:masterfrom
gsmarcil:fix-overwrite-item-ownership
Open

gsmarcil wants to merge 1 commit into
DaveGamble:masterfrom
gsmarcil:fix-overwrite-item-ownership

Conversation

@gsmarcil

@gsmarcil gsmarcil commented Nov 5, 2026

Copy link
Copy Markdown

JSON Patch operations on the root path "" call overwrite_item(), which freed root->string, root->valuestring and root->child unconditionally, ignoring cJSON_IsReference and cJSON_StringIsConst. After a root replace/add, object->string was also freed unconditionally although cJSON_Duplicate() keeps a constant key by pointer.

Applying such a patch to a reference item or to an item with a constant key freed memory the item does not own (double free / use-after-free / invalid free).

  • overwrite_item(): free only what the item owns, as cJSON_Delete() does.
  • After a root replace/add, do not free a constant key and clear cJSON_StringIsConst.
  • Add five regression tests to tests/misc_utils_tests.c.

CVE-2026-117448
Reported by Rachid Marcil (gsmarcil).

JSON Patch operations on the root path "" call overwrite_item(), which
freed root->string, root->valuestring and root->child unconditionally,
ignoring cJSON_IsReference and cJSON_StringIsConst. After a root
replace/add, object->string was also freed unconditionally although
cJSON_Duplicate() keeps a constant key by pointer.

Applying such a patch to a reference item or to an item with a constant
key freed memory the item does not own (double free / use-after-free /
invalid free).

- overwrite_item(): free only what the item owns, as cJSON_Delete() does.
- After a root replace/add, do not free a constant key and clear
  cJSON_StringIsConst.
- Add five regression tests to tests/misc_utils_tests.c.

CVE-2026-117448
Reported by Rachid Marcil (gsmarcil).
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