Repository navigation
xml BUGFIX check characters of CDATA sections - #2649
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
lyxml_parse_value() checks every character of a text or attribute value with ly_getutf8(), but the content of a CDATA section was copied into the value verbatim. Control characters and invalid UTF-8 were therefore accepted inside <![CDATA[...]]> although the same bytes are rejected as plain text, and since the data parsers store terms with is_utf8 set, the string type plugin did not check them either. Such values were printed back as XML that is not well-formed and JSON that is not valid UTF-8. The CDATA content is now checked in the loop that already scans it.
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.
lyxml_parse_value() runs each character of a text or attribute value through ly_getutf8(), which is what rejects invalid UTF-8 and the control characters XML doesn't allow, but the body of a
<![CDATA[...]]>section is memcpy'd into the value with only a whitespace scan. the XML data parser creates terms with is_utf8 set, so the string plugin skips its own string_check_chars() and nothing else ever looks at those bytes.<s xmlns="urn:t"><![CDATA[a\x01b]]></s>, or the same with\xff\xfe, is therefore stored in a plain string leaf while the same bytes as text, through lyd_new_term(), JSON or CBOR are all refused, and printing the tree gives XML with a raw 0x01 that isn't well-formed and JSON that isn't valid UTF-8 (length restrictions get checked against ly_utf8len() of garbage too, nine 0xF0 bytes passlength 1..3). I came across it comparing the CDATA branch with the text branch right below it. the content is now checked in the loop that already walks it, with the same "Invalid character" error the text path gives, and since]can't be a continuation byte the check never reads past the section. the new cases in test_text fail on the current tree and pass with the fix.