Skip to content

json BUGFIX reject non-hex digits in unicode escapes - #2635

Merged
michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:json-unicode-escape-hex
Nov 18, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:json-unicode-escape-hex

Conversation

@affan-arch

Copy link
Copy Markdown

lyjson_string() decodes the four digits of a \uXXXX escape without checking that they are hex: digits go through '0', anything above 'F' is treated as a lowercase letter and everything else as an uppercase one, with the unsigned math wrapping, and only a NUL was rejected. so any four characters turn into some code point, and whenever it lands in the range ly_pututf8() accepts, the value is stored as a character nobody sent: "\u002s" is stored as <, and "\u004"" as +, with the closing quote eaten as the last digit so the string keeps running into the JSON text after it. RFC 8259 wants four HEXDIGs and python's json module rejects both, so a RESTCONF body or anydata content can be tokenized differently by libyang than by whatever looked at it first. the hex character reference path in lyxml_parse_value() already guards this with isxdigit(), so the fix does the same here and reuses the existing error; the new cases in test_string fail on the current tree.

@michalvasko
michalvasko changed the base branch from master to devel November 18, 2026 08:06
@michalvasko

Copy link
Copy Markdown
Member

Thanks, merging into devel.

@michalvasko
michalvasko merged commit 95f8bdb into CESNET:devel Nov 18, 2026
11 of 13 checks passed
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.

2 participants