Repository navigation
Fix NULL dereference in cJSONUtils_GenerateMergePatch on keyless members - #1147
Open
xhon-pelushi wants to merge 1 commit into
Open
xhon-pelushi wants to merge 1 commit into
xhon-pelushi wants to merge 1 commit into
Conversation
generate_merge_patch compared object keys with a plain strcmp, so an object member without a key (e.g. added with cJSON_AddItemToArray) crashed it. Use compare_strings like create_patches does, which also respects case_sensitive, and free the item when it can't be added to the patch because it has no key. Fixes DaveGamble#1143
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1143.
generate_merge_patchcompared object keys with a plainstrcmp, socJSONUtils_GenerateMergePatch/cJSONUtils_GenerateMergePatchCaseSensitivecrashed when either object had a member without a key (easy to get withcJSON_AddItemToArrayon an object). It now usescompare_strings, the same helpercreate_patchesandsort_objectalready use, which handles NULL keys and also followscase_sensitiveso the comparison matches the sort order.A keyless member can't be written into a merge patch, so
cJSON_AddItemToObjectrejects it. The item that was created for it was leaked before; it is now freed and the member is skipped.Added
cjson_utils_generate_merge_patch_should_not_crash_on_keyless_memberstotests/misc_utils_tests.c. With-DENABLE_SANITIZERS=Onit fails without the fix (runtime error: null pointer passed as argument 1at thestrcmp) and passes with it.ctest22/22 with sanitizers, and the plainmakebuild is warning-free.