mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-07-29 22:27:46 +00:00
fix: prevent NULL pointer dereference in cJSON_SetNumberHelper (#991)
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
This commit is contained in:
@@ -410,6 +410,11 @@ loop_end:
|
||||
/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
|
||||
{
|
||||
if (object == NULL)
|
||||
{
|
||||
return (double)NAN;
|
||||
}
|
||||
|
||||
if (number >= INT_MAX)
|
||||
{
|
||||
object->valueint = INT_MAX;
|
||||
|
||||
Reference in New Issue
Block a user