Skip to content

fix: prevent NULL pointer dereference in cJSON_SetNumberHelper#991

Merged
Alanscut merged 1 commit intoDaveGamble:masterfrom
PeterAlfredLee:fix-null-pointer-setnumberhelper
Mar 12, 2026
Merged

fix: prevent NULL pointer dereference in cJSON_SetNumberHelper#991
Alanscut merged 1 commit intoDaveGamble:masterfrom
PeterAlfredLee:fix-null-pointer-setnumberhelper

Conversation

@PeterAlfredLee
Copy link
Contributor

@PeterAlfredLee PeterAlfredLee commented Mar 3, 2026

Add NULL check at the beginning of cJSON_SetNumberHelper to prevent segmentation fault when called with NULL object pointer. The function now returns NAN (Not-a-Number) when object is NULL, consistent with error handling patterns in other cJSON functions.

Add NULL check at the beginning of cJSON_SetNumberHelper to prevent
segmentation fault when called with NULL object pointer. The function
now returns NAN (Not-a-Number) when object is NULL, consistent with
error handling patterns in other cJSON functions.

This fixes a Denial of Service vulnerability (CWE-476) where an
attacker could crash applications using the cJSON library by
triggering this function with a NULL pointer.

Changes:
- cJSON.c: Add NULL check in cJSON_SetNumberHelper
- tests/misc_tests.c: Add test case and math.h include

Security: Fixes NULL pointer dereference vulnerability
@Alanscut Alanscut merged commit b2890c8 into DaveGamble:master Mar 12, 2026
13 checks passed
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.

2 participants