Skip to content

xml BUGFIX check characters of CDATA sections - #2649

Open
affan-arch wants to merge 1 commit into
CESNET:masterfrom
affan-arch:xml-cdata-chars
Open

affan-arch wants to merge 1 commit into
CESNET:masterfrom
affan-arch:xml-cdata-chars

Conversation

@affan-arch

Copy link
Copy Markdown

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

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