]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNodeDevCapPCIDevIommuGroupParseXML: Use virXMLProp*
authorTim Wiederhake <twiederh@redhat.com>
Tue, 18 May 2021 15:04:51 +0000 (17:04 +0200)
committerLaine Stump <laine@redhat.com>
Tue, 18 May 2021 16:27:14 +0000 (12:27 -0400)
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@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/conf/node_device_conf.c

index 861f43f6c46a2ea73b57562ffa7db2c70e260405..332b12f9971c999dc8c70b90b941a35405c8592e 100644 (file)
@@ -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;