[PATCH 06/10] virDomainControllerDefParseXML: Fix broken error reporting when parsing 'index'

Peter Krempa pkrempa at redhat.com
Fri Aug 26 12:20:01 UTC 2022


The code attempted to report an error if the user added the 'index'
attribute to the 'target' element, but neglected to actually return an
error code.

Fix it by using the VIR_XML_PROP_NONNEGATIVE flag for virXMLPropInt
which refuses user passed negative numbers.

Fixes: 020dd80ecbd
Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/domain_conf.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3ff9fffba8..a9a2afc7f1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8233,15 +8233,10 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
                                          &def->opts.pciopts.hotplug) < 0)
                 return NULL;

-            if ((rc = virXMLPropInt(targetNodes[0], "index", 0, VIR_XML_PROP_NONE,
-                                    &def->opts.pciopts.targetIndex,
-                                    def->opts.pciopts.targetIndex)) < 0)
+            if (virXMLPropInt(targetNodes[0], "index", 0, VIR_XML_PROP_NONNEGATIVE,
+                              &def->opts.pciopts.targetIndex,
+                              def->opts.pciopts.targetIndex) < 0)
                 return NULL;
-
-            if ((rc == 1) && def->opts.pciopts.targetIndex == -1)
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("Invalid target index '%i' in PCI controller"),
-                               def->opts.pciopts.targetIndex);
         }
     } else if (ntargetNodes > 1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
-- 
2.37.1



More information about the libvir-list mailing list