Skip to content

fix(cjson_utils): add NULL check for cJSON_malloc in FindPointerFromObjectTo (#1049)#1055

Open
JIgar-maheshwari-dev wants to merge 1 commit into
DaveGamble:developfrom
JIgar-maheshwari-dev:fix/1049-null-check-cjson-utils
Open

fix(cjson_utils): add NULL check for cJSON_malloc in FindPointerFromObjectTo (#1049)#1055
JIgar-maheshwari-dev wants to merge 1 commit into
DaveGamble:developfrom
JIgar-maheshwari-dev:fix/1049-null-check-cjson-utils

Conversation

@JIgar-maheshwari-dev

@JIgar-maheshwari-dev JIgar-maheshwari-dev commented Jul 22, 2026

Copy link
Copy Markdown

Summary of Changes

Fixes #1049 #1007

  • Bug Fix: Added a missing NULL check following cJSON_malloc for full_pointer inside FindPointerFromObjectTo (cJSON_Utils.c).
  • Memory Safety: Ensures target_pointer is freed and NULL is returned gracefully if memory allocation fails, preventing a SIGSEGV crash in sprintf.
  • Unit Test: Added tests/oom_test.c using Unity hooks to simulate allocation failure and verify safe return behavior in C90 compliance.

Testing

  • Verified locally on Linux (GCC / CMake).
  • Confirmed that unpatched code crashes on OOM, while patched code passes oom_test cleanly.

…bjectTo (DaveGamble#1049)

- Add missing NULL check for full_pointer allocation to prevent SIGSEGV on OOM.
- Free target_pointer and return NULL safely if full_pointer fails to allocate.
- Add oom_test unit test to verify graceful handling of memory allocation failure.

Signed-off-by: JIgar-maheshwari-dev <maheshwarijigar656@gmail.com>
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