Skip to content

fix: handle allocation failure in cJSONUtils_FindPointerFromObjectTo#1042

Draft
xuh0923 wants to merge 1 commit into
DaveGamble:masterfrom
xuh0923:fix-utils-find-pointer-allocation-check
Draft

fix: handle allocation failure in cJSONUtils_FindPointerFromObjectTo#1042
xuh0923 wants to merge 1 commit into
DaveGamble:masterfrom
xuh0923:fix-utils-find-pointer-allocation-check

Conversation

@xuh0923

@xuh0923 xuh0923 commented Jun 27, 2026

Copy link
Copy Markdown

Issue
This change fixes a missing allocation failure check in cJSONUtils_FindPointerFromObjectTo.

When cJSON_malloc returns NULL while building the JSON pointer path, the function may dereference a null pointer before returning. That makes the failure path unsafe in low-memory situations.

Changes

  • add missing NULL checks after allocating full_pointer in the array and object branches of cJSONUtils_FindPointerFromObjectTo
  • add a regression test that uses failing hooks to verify the function returns NULL for both branches when allocation fails

Verification

  • build and run tests/misc_utils_tests.c with gcc -Wall -Wextra -Werror -std=c89
  • build and run tests/old_utils_tests.c with gcc -Wall -Wextra -Werror -std=c89

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