Repository navigation
xpath BUGFIX value functions on nodes without schema - #2612
Merged
michalvasko merged 1 commit intoNov 3, 2026
Merged
Conversation
enum-value(), bit-is-set() and deref() read the schema of the first argument node without checking it, so they crashed on the opaque dummy node used for the when of a missing node and on the root node. Such a node has no value, so enum-value() returns NaN, bit-is-set() false and deref() an empty node-set, as derived-from() already does. Fixes CESNET#2604
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.
What
enum-value(),bit-is-set()andderef()now check that the first node of their node-set argument is an element with a schema node before reading its schema and value. Any other first node has no value, so:enum-value()returns NaN (RFC 7950, section 10.5.1: "If the first node in "nodes" is not of type "enumeration", it returns NaN"),bit-is-set()returns false (section 10.6.1),deref()returns an empty node-set.derived-from()andderived-from-or-self()already skip such nodes (if (!sleaf || !(sleaf->nodetype & LYD_NODE_TERM))inxpath_derived_()), and the three functions now behave the same way.Why
lyd_validate_dummy_when()evaluates thewhenof a missing node on an opaque dummy node created bylyd_new_opaq(), whoseschemaisNULL. The three functions dereferenced thatNULLschema, so validating a schema such as this one crashed, even on empty input:RFC 7950, section 7.21.5, gives the dummy node no value: "replacing all instances of the data node for which the "when" statement is defined with a single dummy node with the same name, but with no value and no children. If no such instance exists, the dummy node is tentatively created." Treating it as a node without a value is therefore the specified result, not only a way to avoid the crash.
The same missing check also crashed on the root node, which is stored in the set with a
NULLnode: for examplemust "enum-value(/) = 1",bit-is-set(/, 'f')orderef(/). The type check covers this case too. A metadata node is no longer read as if it were a data node; like the root node and an opaque node, it now gives no value to these three functions. A text node (text()) is skipped as well, asxpath_derived_()already does; before, these three functions read the value of its parent element.Fixes #2604
Test
test_no_valueintests/utests/basic/test_xpath.c:whenis true only if the function finds no value (string(enum-value(.)) = 'NaN',not(bit-is-set(., 'f')),not(deref(.)),not(derived-from-or-self(., 'c:one'))); each container alone is refused withMandatory node "v" instance does not exist., which shows that the dummy node is read as having no value;lyd_eval_xpath()on a small tree checksstring(enum-value(/)) = 'NaN'(true),bit-is-set(/, 'f')(false) andderef(/)(false).Before the fix,
utest_xpathstops attest_no_valuewith a segmentation fault (16 of 17 tests pass). After the fix, all 17 pass,utest_validationpasses (22 of 22), and the wholectestrun passes (69 of 69; Debug build, GCC 13.3, aarch64).