Skip to content
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

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

mongobaba
Copy link
Contributor

No description provided.

@@ -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++)
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;

Copy link
Collaborator

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.

Copy link
Collaborator

@Alanscut Alanscut left a 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.

@Alanscut Alanscut merged commit 2f6fc7f into DaveGamble:master Nov 12, 2020
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this pull request Sep 6, 2021
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]>
halstead pushed a commit to openembedded/meta-openembedded that referenced this pull request Sep 17, 2021
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]>
daregit pushed a commit to daregit/yocto-combined that referenced this pull request May 22, 2024
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]>
daregit pushed a commit to daregit/yocto-combined that referenced this pull request May 22, 2024
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]>
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