Skip to content

parser cbor BUGFIX check characters of text strings - #2602

Open
affan-arch wants to merge 1 commit into
CESNET:develfrom
affan-arch:cbor-string-chars
Open

affan-arch wants to merge 1 commit into
CESNET:develfrom
affan-arch:cbor-string-chars

Conversation

@affan-arch

Copy link
Copy Markdown

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.

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.
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.

1 participant