Skip to content

Apply JSON Patch arrays atomically (CVE-2026-67217) - #1114

Open
w4ffl35 wants to merge 3 commits into
DaveGamble:masterfrom
w4ffl35:fix/atomic-apply-patches
Open

w4ffl35 wants to merge 3 commits into
DaveGamble:masterfrom
w4ffl35:fix/atomic-apply-patches

Conversation

@w4ffl35

@w4ffl35 w4ffl35 commented Oct 26, 2026 •

Copy link
Copy Markdown

Apply each JSON Patch array to duplicates and commit only after every operation succeeds. Failed patches leave the original document untouched, the caller's pointer stays stable, and patch arrays stored inside the document remain valid during iteration.

Preserve the target's next/prev links when committing a successful patch to a non-root node. Regression cases cover the first, middle and last child in both objects and arrays through both ApplyPatches entry points.

Validation at 1e48286:

  • The two new sibling tests fail against the previous PR head b269a37 (2 failures in 5 tests).
  • Plain GCC build with ENABLE_CJSON_UTILS=ON and BUILD_SHARED_LIBS=OFF: CTest 22/22 pass.
  • GCC with -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-pie -no-pie, ASAN_OPTIONS=detect_leaks=1 and UBSAN_OPTIONS=halt_on_error=1: CTest 22/22 pass.
  • Existing failure-rollback and successful multi-operation cases remain covered.

Behavior change: failed patch arrays now leave the document unchanged instead of keeping earlier operations applied. Error status codes are unchanged. Duplicating the document and patch array increases memory use and execution time.

AI assistance: This report and patch were prepared with AI assistance. Validation commands and results are recorded above.

cJSONUtils_ApplyPatches{,CaseSensitive} applied operations directly to
the caller's document and returned on the first failure, leaving
earlier operations applied: an attacker-supplied patch could destroy
data and then fail validation. Run all operations against a duplicate
and commit to the original only when every operation succeeds, keeping
the caller's pointer stable. Working from duplicates also closes the
use-after-free when the patch array itself lives inside the patched
document. Add regression tests for rollback and success paths.
Replace the stale NOT-atomic advisory comment: cJSONUtils_ApplyPatches
and cJSONUtils_ApplyPatchesCaseSensitive are now atomic (all-or-nothing).
Returns-0-for-success contract is unchanged.
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