Skip to content

parsers BUGFIX read past the end of bounded input - #2660

Merged
michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:bounded-input-overread
Dec 1, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:bounded-input-overread

Conversation

@affan-arch

Copy link
Copy Markdown

parsing from an exactly-sized ly_in_new_memory_chunk() buffer reads past its end (asan heap-buffer-overflow, {"":true} is enough) because skip_section() and lyjson_number_is_zero() dereference the input before the bounds check, a zero-length member name or instance-identifier value reaches lys_find_child_node() and ly_path_parse() where a length of 0 means NULL-terminated, and strtoll() plus three xml error-message formats run to the first NUL byte.

The bounded input support lets a caller parse from an exactly-sized
buffer with no terminating byte (ly_in_new_memory_chunk(),
lyd_parse_data_mem_len()), but several places still assume one is
there.

skip_section() dereferences the input in the for condition before
lyxml_check_read() runs and both of its checks are off by one, so a
document ending inside a comment, a processing instruction or a
declaration reads past the end. lyjson_number_is_zero() reads in[1]
without comparing it against end and lyjson_exp_number() converts the
exponent with strtoll(), which runs to the first NUL byte.
lyd_parser_get_snode() and lyplg_type_lypath_new() forward a zero
length to lys_find_child_node() and ly_path_parse(), where 0 means
NULL-terminated, so an empty JSON member name or instance-identifier
value is strlen()ed. The "Identifier", "Unknown XML section" and
"Entity reference" messages format the raw input with %s or a fixed
precision, so vasprintf() scans past the end as well.

@michalvasko michalvasko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, seems I missed some cases.

@michalvasko
michalvasko merged commit c77f8b4 into CESNET:devel Dec 1, 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