]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: check port range even for USB hubs
authorJán Tomko <jtomko@redhat.com>
Mon, 30 Jan 2017 14:56:10 +0000 (15:56 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 13 Feb 2017 12:08:36 +0000 (13:08 +0100)
Move the range check introduced by commit 2650d5e into
virDomainUSBAddressFindPort. That way both virDomainUSBAddressRelease
and virDomainUSBAddressSetAddHub can benefit from it.

Reported-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_addr.c

index e0adea9f9288ac31fbd5e19e15f05a2c58ee1574..1649d84eaa7d8c714350a66b0a9a6f80d285d64b 100644 (file)
@@ -1785,7 +1785,7 @@ virDomainUSBAddressFindPort(virDomainUSBAddressSetPtr addrs,
                             const char *portStr)
 {
     virDomainUSBAddressHubPtr hub = NULL;
-    ssize_t i, lastIdx;
+    ssize_t i, lastIdx, targetPort;
 
     if (info->addr.usb.bus >= addrs->nbuses ||
         !addrs->buses[info->addr.usb.bus]) {
@@ -1820,7 +1820,15 @@ virDomainUSBAddressFindPort(virDomainUSBAddressSetPtr addrs,
         }
     }
 
-    *targetIdx = info->addr.usb.port[lastIdx] - 1;
+    targetPort = info->addr.usb.port[lastIdx] - 1;
+    if (targetPort >= virBitmapSize(hub->portmap)) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("requested USB port %s not present on USB bus %u"),
+                       portStr, info->addr.usb.bus);
+        return NULL;
+    }
+
+    *targetIdx = targetPort;
     return hub;
 }
 
@@ -2070,13 +2078,6 @@ virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
                                                   portStr)))
         goto cleanup;
 
-    if (targetPort >= virBitmapSize(targetHub->portmap)) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("requested USB port %s not present on USB bus %u"),
-                       portStr, info->addr.usb.bus);
-        goto cleanup;
-    }
-
     if (virBitmapIsBitSet(targetHub->portmap, targetPort)) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("Duplicate USB address bus %u port %s"),