[libvirt PATCH 10/10] virNodeDevCapPCIDevIommuGroupParseXML: Use virXMLProp*

Tim Wiederhake twiederh at redhat.com
Tue May 18 15:04:51 UTC 2021


This strictens the parser to disallow negative values (interpreted as
`UINT_MAX + value + 1`) for attribute `number`. Allowing negative
numbers to be interpreted this way makes no sense for this attribute.

Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/conf/node_device_conf.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 861f43f6c4..332b12f997 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1557,25 +1557,14 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt,
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree xmlNodePtr *addrNodes = NULL;
-    g_autofree char *numberStr = NULL;
     int nAddrNodes;
     size_t i;
 
     ctxt->node = iommuGroupNode;
 
-    numberStr = virXMLPropString(iommuGroupNode, "number");
-    if (!numberStr) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       "%s", _("missing iommuGroup number attribute"));
+    if (virXMLPropUInt(iommuGroupNode, "number", 10, VIR_XML_PROP_REQUIRED,
+                       &pci_dev->iommuGroupNumber) < 0)
         return -1;
-    }
-    if (virStrToLong_ui(numberStr, NULL, 10,
-                        &pci_dev->iommuGroupNumber) < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid iommuGroup number attribute '%s'"),
-                       numberStr);
-        return -1;
-    }
 
     if ((nAddrNodes = virXPathNodeSet("./address", ctxt, &addrNodes)) < 0)
         return -1;
-- 
2.26.3




More information about the libvir-list mailing list