Skip to content

tree data: duplicate anydata children into target context - #2565

Merged
michalvasko merged 1 commit into
CESNET:develfrom
Yeaseen:fix-anydata-cross-ctx-dup
Aug 28, 2026
Merged

tree data: duplicate anydata children into target context#2565
michalvasko merged 1 commit into
CESNET:develfrom
Yeaseen:fix-anydata-cross-ctx-dup

Conversation

@Yeaseen

@Yeaseen Yeaseen commented Aug 26, 2026

Copy link
Copy Markdown

Summary

Fix a use-after-free in cross-context duplication of data trees containing
anydata XML subtrees.

This addresses GHSA-jq97-j23h-2vqw:
GHSA-jq97-j23h-2vqw

Problem

lyd_dup_siblings_to_ctx() is expected to duplicate a data tree into the target
context. However, when duplicating an anydata node that stores its value as a
child subtree, the embedded children were copied with lyd_dup_siblings().

That preserves references to the source context. If the source tree and source
context are freed after successful duplication, later operations on the duplicate
can access freed memory. One affected path is XPath traversal through
lyd_trim_xpath().

Fix

Duplicate anydata child subtrees with lyd_dup_siblings_to_ctx() and
LYD_CTX(trg) so embedded children are copied into the same target context as
the containing anydata node.

Add a regression test that duplicates an anydata XML subtree into a second
context, destroys the original context, and then evaluates XPath on the
duplicate.

Verification

I ran the advisory reproducer against an ASan/UBSan build with this fix applied.
The reproducer completes successfully and no use-after-free is reported.

@michalvasko

Copy link
Copy Markdown
Member

Already fixed in the devel branch but if you rebase (remove the fix), I can still merge the test.

@Yeaseen
Yeaseen force-pushed the fix-anydata-cross-ctx-dup branch from 778b864 to c466bcf Compare August 27, 2026 17:17
@Yeaseen
Yeaseen changed the base branch from master to devel August 27, 2026 17:18
@Yeaseen

Yeaseen commented Aug 27, 2026

Copy link
Copy Markdown
Author

@michalvasko Done, thanks. I rebased onto devel, removed the duplicate fix, and kept only the regression test.

@michalvasko
michalvasko merged commit f12f5b2 into CESNET:devel Aug 28, 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