Skip to content

parser json BUGFIX use-after-free of escaped member names - #2593

Merged
michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:json-member-name-uaf
Oct 20, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:json-member-name-uaf

Conversation

@affan-arch

Copy link
Copy Markdown

Repro: parse {"a:foo":"xxx","@a:foo":{"a:hin\u0074":1}} with an ASan build, or run regress_fuzz_lyd_parse_mem_json on the existing pull1626 corpus file; both report a heap-use-after-free (in ly_strncmp from lyd_get_meta_annotation, and in dict_insert from lyd_create_attr). A RESTCONF notification starting with {"ietf-restconf:notificatio\u006e":...} hits the same thing in lyd_create_opaq via lydjson_envelope().
Cause: a member name with escapes is decoded into a buffer owned by the JSON context, and lydjson_meta_attr_instance() / lydjson_envelope() keep name/prefix pointing into it across the lyjson_ctx_next() that frees it.
Fix: take ownership with lyjson_ctx_give_dynamic_value(), same as lydjson_subtree_r() already does for node names. Both cases are covered in test_parser_json.c; they abort under ASan without the fix, and the full ctest run (including the fuzz regression) passes with it.

A member name containing escape sequences is decoded into a buffer
owned by the JSON context, which is freed by the next
lyjson_ctx_next(). lydjson_meta_attr_instance() and lydjson_envelope()
kept using the name/prefix pointing into it after that call, so take
ownership of the buffer the same way lydjson_subtree_r() does.
@michalvasko
michalvasko changed the base branch from master to devel October 20, 2026 09:07
@michalvasko

michalvasko commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Um, yes, thanks, I will also fix the tests. But I have changed the base branch to devel, we do not merge PRs into master.

@michalvasko
michalvasko merged commit 005a8b4 into CESNET:devel Oct 20, 2026
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