Repository navigation
parser cbor BUGFIX check characters of text strings - #2602
Open
affan-arch wants to merge 1 commit into
Open
affan-arch wants to merge 1 commit into
affan-arch wants to merge 1 commit into
Conversation
lydcbor_item_to_string() copied CBOR strings verbatim while terms are created with is_utf8 set, so the string plugin skipped its character check. Values with NUL bytes, control characters or invalid UTF-8 were accepted, and a value with an embedded NUL is inserted into the dictionary with its full length but removed by strlen(), dropping a reference of a different record.
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.
Repro: with another tree holding the string "ab", parse and free the CBOR map {"cbor-test:lf-str": "ab\0cd"}. reading the first tree's value afterwards is a heap use-after-free under ASan, the string was freed in _lydict_remove().
Cause: lydcbor_item_to_string() copies text strings verbatim, but terms are created with is_utf8 set, so the string plugin skips its own character check. the value is inserted into the dictionary with length 5 and removed by strlen(), which drops the reference of the "ab" record instead. NUL bytes, control characters and invalid UTF-8 get stored this way too, where the JSON and XML parsers reject them.
Fix: check the characters with ly_checkutf8() where CBOR strings are converted, which covers member names, values, metadata and opaque nodes. two cases added to test_invalid_input.