Skip to content

plugins types BUGFIX read past short date values - #2637

Merged
michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:date-short-value
Nov 18, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:date-short-value

Conversation

@affan-arch

Copy link
Copy Markdown

Repro: with l2 a yang:date leaf, parsing <l2 xmlns="urn:tests:a">2</l2><l2nz xmlns="urn:tests:a">2005-05-31</l2nz> with LYD_PARSE_STORE_ONLY succeeds, the "date" being parsed out of the markup of the next element. with &#50; instead of 2 the value sits in an exact-size heap buffer and the read runs past it, and lyd_new_term() with LYD_NEW_VAL_STORE_ONLY on a "2" placed right before a no-access page dies with an access violation.
Cause: lyplg_type_store_date() builds the date-and-time string with "%.*sT00:00:00%.*s", 10, value, value_size - 10, value + 10, which only works if the pattern already guaranteed a full date. store-only skips the pattern, so for a shorter value the second precision is negative, printf ignores it and %s reads from value + 10 until it hits a NUL.
Fix: reject values shorter than a date before building the string, with the same "Failed to parse" error the date-no-zone branch uses. the new cases in test_data_xml fail on the current tree and pass with the fix.

lyplg_type_store_date() builds a date-and-time string from the first
10 characters of the value and the rest after them, relying on the
pattern to guarantee a full date. With LYPLG_TYPE_STORE_ONLY the
pattern is skipped, so for a shorter value the precision of the second
%.*s is negative and asprintf() reads from value + 10, past the end of
the value, until a NUL byte. An escaped value such as &CESNET#50; is passed
in an exact-size heap buffer, and a value pointing into the input is
parsed together with the following markup, so <l2>2</l2> followed by
another element was accepted as a date.
@michalvasko

Copy link
Copy Markdown
Member

Thanks, such invalid memory access needs to be avoided but also the LYD_PARSE_STORE_ONLY flag expects the validation is not required because it has been performed already before. If not, it is incorrect usage of the API.

@michalvasko
michalvasko merged commit 41838b7 into CESNET:devel Nov 18, 2026
14 of 15 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