Skip to content

xpath BUGFIX evaluate comment() as an empty node set - #2665

Open
Mohil-Ahuja wants to merge 1 commit into
CESNET:develfrom
Mohil-Ahuja:xpath-comment-nodetype
Open

Mohil-Ahuja wants to merge 1 commit into
CESNET:develfrom
Mohil-Ahuja:xpath-comment-nodetype

Conversation

@Mohil-Ahuja

Copy link
Copy Markdown

The tokenizer accepts comment() as a NodeType (next to node() and text()), but eval_node_type_with_predicate() only handles node and text. A debug build fails on assert(exp->tok_len[*tok_idx] == 4), and a release build falls through to xpath_pi_text(), so comment() selects the text of the context nodes:

/* tree: <foo xmlns="urn:tests:a">val</foo> */
lyd_eval_xpath(tree, "/a:foo/comment()", &r);   /* r == 1 */

Data trees have no comment nodes, so comment() now always gives an empty node set, and for schema nodes it is handled the same way as text(). The test is added to test_no_value in test_xpath.c. I found it by fuzzing lyd_eval_xpath.

The tokenizer accepts comment() as a NodeType, but the evaluator only
knew node() and text(), so comment() was evaluated as text() and
selected the text of the context nodes (an assert caught it in debug
builds). Data trees have no comment nodes, so it selects nothing now.
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.

1 participant