Skip to content

fix: NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input #1035 - #1066

Open
rishi-ragavan wants to merge 2 commits into
DaveGamble:masterfrom
rishi-ragavan:fix-1035-null-error-ptr
Open

fix: NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input #1035#1066
rishi-ragavan wants to merge 2 commits into
DaveGamble:masterfrom
rishi-ragavan:fix-1035-null-error-ptr

Conversation

@rishi-ragavan

Copy link
Copy Markdown

Fixes #1035

Overview

There was a possibility that cJSON_GetErrorPtr() could return a NULL pointer and later cause segmentation fault when dereferencing.

Fix

Whenever the global_error.json is NULL, instead of returning the global_error.json along with the global_error.position, I create a new safe_to_dereference empty string and return that.

Validation

Cleanly builds and passes all the tests.

setting global_error to NULL and returning.
Fixes DaveGamble#1035

The function cJSON_ParseWithLengthOpts() didn't
change global_error when returning NULL, so I added
an else statement that made sure to set global_error
to an empty string so it can later be dereferenced
without an segementation fault error.
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.

NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input

1 participant