Skip to content

Fix mapped input dangling - #429

Merged
vstakhov merged 2 commits into
vstakhov:masterfrom
tregua87:fix-mapped-input-dangling
Oct 7, 2026
Merged

vstakhov merged 2 commits into
vstakhov:masterfrom
tregua87:fix-mapped-input-dangling

Conversation

@tregua87

@tregua87 tregua87 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Fix #428

tregua87 and others added 2 commits October 7, 2026 13:20
ucl_parser_add_fd_full and ucl_parser_add_file_full mmap the input, parse
it, then munmap it. Two things still point into the mapping afterwards.

Zero-copy objects: with UCL_PARSER_ZEROCOPY, keys and string values are
pointers into the input, so after a successful ucl_parser_add_fd a lookup
reads unmapped memory. The flag documents zero-copy 'if possible', and for
a file it never is, because the library releases the buffer itself.

The chunk: it stays in parser->chunks with pos/end into the mapping, so
after a parse error ucl_parser_chunk_peek and ucl_parser_chunk_skip
dereference it.

Add a helper used by both: parse with UCL_PARSER_ZEROCOPY temporarily
cleared, unmap, and clear begin/pos/end/remain of the chunk that referred to
it - chunk_peek and chunk_skip already treat a NULL pos as no data.
Zero-copy for ucl_parser_add_chunk*, where the caller owns the memory, is
unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W3aXdPKAnVwjiNtZstnmPj

@vstakhov vstakhov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM. Reproduced both cases from the issue on master under ASan: the zerocopy lookup after ucl_parser_add_fd(), and chunk peek/skip after a failed parse. Both are clean on this branch.

Non-blocking follow-up: .include (ucl_include_file_single) has the same pattern. It mmaps, parses with the caller's UCL_PARSER_ZEROCOPY, then munmaps. So zerocopy + .include from caller-owned input still leaves keys dangling, and a failed include leaves a chunk pointing into the unmapped file.

@vstakhov
vstakhov merged commit 800b9e3 into vstakhov:master Oct 7, 2026
4 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.

ucl_object_lookup_path_char() with a NUL separator reads past the end of the path

2 participants