Skip to content

parser cbor BUGFIX metadata coupled with the wrong node - #2632

Merged
michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:cbor-meta-attr-node
Nov 16, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:cbor-meta-attr-node

Conversation

@affan-arch

Copy link
Copy Markdown

lydcbor_subtree_r() walks every member of a CBOR map in one loop, unlike lydjson_subtree_r() which is called once per member, so attr_node set for a "@" member (the parent's own metadata) is never cleared and every later "@name" member in that map gets coupled with the parent instead of the named sibling. libyang's own output shows it: {"cbor-test:cont-root":{"@":{"cbor-test:a1":"val1"},"lf-root-str":"x","@lf-root-str":{"cbor-test:a2":5}}} printed as CBOR and parsed back ends up with a2 on cont-root, and leaf-list metadata in a list entry that has its own "@" is rejected with "Missing CBOR data instance #2". when the parent is opaque, which is always the case for anydata content parsed with default options, a following "@mod:leaf-list" array walks past the parent and the error path in lydcbor_meta_attr() reads prev->schema->module of an opaque node, so a small untrusted CBOR document crashes the parser (NULL read, ASan SEGV). the same read is reachable without the stale pointer from an opaque leaf-list instance, e.g. {"cbor-test:ll-intg32":["x"],"@cbor-test:ll-intg32":[null,null]} with LYD_PARSE_OPAQ. it showed up while comparing the CBOR member loop with the JSON one. the fix clears attr_node per member and builds the message from snode, which is what picks the leaf-list branch there; test_attributes_parent in test_cbor.c covers all three cases and fails without the change.

lydcbor_subtree_r() processes all the members of a map in one call,
but attr_node, set for a "@" member, was not reset for the following
members, so any later "@name" metadata were coupled with the parent
instead of the named sibling. With an opaque parent, and also for
opaque leaf-list instances, the leaf-list error path then dereferenced
the NULL schema of the previous instance.
@michalvasko

Copy link
Copy Markdown
Member

Thanks, merging.

@michalvasko
michalvasko merged commit b67fff3 into CESNET:devel Nov 16, 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