Fix: libcib: Prevent based or cibadmin from crashing when handling an XPath query for an attribute #3980
+38
−7
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.
With 5fe98f4 in 3.0.1, if an XPath query for an attribute resulted in a
single match, for example:
, based would encounter a fatal assertion in pcmk__xml_copy():
The assertion wouldn't be triggered if there were multiple matches for an
attribute, despite the fact that only the last match would be displayed:
But in case --node-path option was anyhow specified, cibadmin would
encounter a fatal assertion in output_xml_id():
If --no-children option was anyhow specified, the attribute name would be
displayed as an element name and the value wouldn't be shown:
This commit fixes the issues by handling non-element matches separately.
Besides, instead of being displayed with a vague element name "xpath-query",
now a matching attribute is displayed with the corresponding element name
and the ID if present, so that the output is meaningful:
Multiple matches are all displayed:
Also, although cibadmin --node-path option is deprecated, the previous
behavior is restored by handling the corresponding element of a
non-element match instead of returning nothing:
And --node-path option is respected even if --no-children is also specified.