Repository navigation
parsers BUGFIX read past the end of bounded input - #2660
Merged
Merged
Conversation
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
approved these changes
Dec 1, 2026
michalvasko
left a comment
Member
There was a problem hiding this comment.
Thanks, seems I missed some cases.
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.
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.