libxml2/libxml2-2.12.5-xmllint-error-code.patch
David King c879317c75 Fix xmllint error code (RHEL-126768)
Resolves: RHEL-126768
2026-01-26 15:00:45 +00:00

89 lines
3.3 KiB
Diff

From 387a952bdb7a4364100f009043e94e1bf44c6197 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Mon, 12 Feb 2024 16:45:16 +0100
Subject: [PATCH] xmllint: Return error code if XPath returns empty nodeset
Return an error code as before but make it possible to distinguish from
real errors.
Fixes #690.
---
doc/xmllint.xml | 11 ++++++++++-
xmllint.c | 24 +++++++++++++-----------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/doc/xmllint.xml b/doc/xmllint.xml
index b81da3aa7..8bc665216 100644
--- a/doc/xmllint.xml
+++ b/doc/xmllint.xml
@@ -575,7 +575,9 @@
result. In case of a nodeset result, each node in the
node set is serialized in full in the output. In case
of an empty node set the "XPath set is empty" result
- will be shown and an error exit code will be returned.
+ will be shown and exit code 11 will be returned..
+ This feature is EXPERIMENTAL. Implementation details can
+ change without futher notice.
</para>
</listitem>
</varlistentry>
@@ -945,6 +947,13 @@
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><errorcode>11</errorcode></term>
+ <listitem>
+ <para>XPath result is empty</para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
diff --git a/xmllint.c b/xmllint.c
index 21dbe7d24..5c26c3fe8 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -86,17 +86,18 @@
#endif
typedef enum {
- XMLLINT_RETURN_OK = 0, /* No error */
- XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
- XMLLINT_ERR_DTD = 2, /* Error in DTD */
- XMLLINT_ERR_VALID = 3, /* Validation error */
- XMLLINT_ERR_RDFILE = 4, /* CtxtReadFile error */
- XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
- XMLLINT_ERR_OUT = 6, /* Error writing output */
- XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
- XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
- XMLLINT_ERR_MEM = 9, /* Out of memory error */
- XMLLINT_ERR_XPATH = 10 /* XPath evaluation error */
+ XMLLINT_RETURN_OK = 0, /* No error */
+ XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
+ XMLLINT_ERR_DTD = 2, /* Error in DTD */
+ XMLLINT_ERR_VALID = 3, /* Validation error */
+ XMLLINT_ERR_RDFILE = 4, /* CtxtReadFile error */
+ XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
+ XMLLINT_ERR_OUT = 6, /* Error writing output */
+ XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
+ XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
+ XMLLINT_ERR_MEM = 9, /* Out of memory error */
+ XMLLINT_ERR_XPATH = 10, /* XPath evaluation error */
+ XMLLINT_ERR_XPATH_EMPTY = 11 /* XPath result is empty */
} xmllintReturnCode;
#ifdef LIBXML_DEBUG_ENABLED
static int shell = 0;
@@ -2019,6 +2020,7 @@ static void doXPathDump(xmlXPathObjectPtr cur) {
xmlOutputBufferPtr buf;
if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr <= 0)) {
+ progresult = XMLLINT_ERR_XPATH_EMPTY;
if (!quiet) {
fprintf(stderr, "XPath set is empty\n");
}
--
GitLab