-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix several null pointer problems on allocation failure #526
Conversation
@@ -2548,7 +2548,12 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) | |||
} | |||
|
|||
a = cJSON_CreateArray(); | |||
for(i = 0; a && (i < (size_t)count); i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when allocation failure, cJSON_CreateArray()
will return NULL, then it won't enter the for loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it won't enter the for loop, but 'a->child' will crush.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line after for loop, a->child->prev = n;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I didn't notice that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for(i = 0; a && (i < (size_t)count); i++)
is equal to
if (!a)
{
return NULL;
}
for(i = 0; a && (i < (size_t)count); i++)
there is no need to optimize it.
Fixes: Fix potential core dumped for strrchr, see DaveGamble/cJSON#546 Fix null pointer crash in cJSON_CreateXxArray, see DaveGamble/cJSON#538 Fix several null pointer problems on allocation failure, see DaveGamble/cJSON#526 Fix a possible dereference of null pointer, see DaveGamble/cJSON#519 Fix windows build failure about defining nan, see DaveGamble/cJSON#518 Signed-off-by: Wang Mingyu <[email protected]> Signed-off-by: Khem Raj <[email protected]>
Fixes: Fix potential core dumped for strrchr, see DaveGamble/cJSON#546 Fix null pointer crash in cJSON_CreateXxArray, see DaveGamble/cJSON#538 Fix several null pointer problems on allocation failure, see DaveGamble/cJSON#526 Fix a possible dereference of null pointer, see DaveGamble/cJSON#519 Fix windows build failure about defining nan, see DaveGamble/cJSON#518 Signed-off-by: Wang Mingyu <[email protected]> Signed-off-by: Khem Raj <[email protected]> (cherry picked from commit fa00ac0) Signed-off-by: Armin Kuster <[email protected]>
Fixes: Fix potential core dumped for strrchr, see DaveGamble/cJSON#546 Fix null pointer crash in cJSON_CreateXxArray, see DaveGamble/cJSON#538 Fix several null pointer problems on allocation failure, see DaveGamble/cJSON#526 Fix a possible dereference of null pointer, see DaveGamble/cJSON#519 Fix windows build failure about defining nan, see DaveGamble/cJSON#518 Signed-off-by: Wang Mingyu <[email protected]> Signed-off-by: Khem Raj <[email protected]>
Fixes: Fix potential core dumped for strrchr, see DaveGamble/cJSON#546 Fix null pointer crash in cJSON_CreateXxArray, see DaveGamble/cJSON#538 Fix several null pointer problems on allocation failure, see DaveGamble/cJSON#526 Fix a possible dereference of null pointer, see DaveGamble/cJSON#519 Fix windows build failure about defining nan, see DaveGamble/cJSON#518 Signed-off-by: Wang Mingyu <[email protected]> Signed-off-by: Khem Raj <[email protected]>
No description provided.