render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
3e5111
From 74f7abdf0e567914abc12319f1e3d723e18d0d6d Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <74f7abdf0e567914abc12319f1e3d723e18d0d6d@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Thu, 13 Apr 2017 12:05:48 +0200
3e5111
Subject: [PATCH] qemu: do not crash on USB address with no port and invalid
3e5111
 bus
3e5111
MIME-Version: 1.0
3e5111
Content-Type: text/plain; charset=UTF-8
3e5111
Content-Transfer-Encoding: 8bit
3e5111
3e5111
Properly error out when the user requests a port from a bus
3e5111
that does not have a controller present in the domain XML.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1441589
3e5111
(cherry picked from commit b003b9781b6ae633cfe4fdf6b9620ca246fa2432)
3e5111
Signed-off-by: Ján Tomko <jtomko@redhat.com>
3e5111
---
3e5111
 src/conf/domain_addr.c                             |  3 ++-
3e5111
 .../qemuxml2argv-usb-bus-missing.xml               | 22 ++++++++++++++++++++++
3e5111
 tests/qemuxml2argvtest.c                           |  3 +++
3e5111
 3 files changed, 27 insertions(+), 1 deletion(-)
3e5111
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-bus-missing.xml
3e5111
3e5111
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
3e5111
index 35bdc3453..8b6109199 100644
3e5111
--- a/src/conf/domain_addr.c
3e5111
+++ b/src/conf/domain_addr.c
3e5111
@@ -2009,7 +2009,8 @@ virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs,
3e5111
 
3e5111
     if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
3e5111
         VIR_DEBUG("A USB port on bus %u was requested", info->addr.usb.bus);
3e5111
-        if (!addrs->buses[info->addr.usb.bus]) {
3e5111
+        if (info->addr.usb.bus >= addrs->nbuses ||
3e5111
+            !addrs->buses[info->addr.usb.bus]) {
3e5111
             virReportError(VIR_ERR_XML_ERROR,
3e5111
                            _("USB bus %u requested but no controller "
3e5111
                              "with that index is present"), info->addr.usb.bus);
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-bus-missing.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-bus-missing.xml
3e5111
new file mode 100644
3e5111
index 000000000..831a4c0af
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-bus-missing.xml
3e5111
@@ -0,0 +1,22 @@
3e5111
+<domain type='qemu'>
3e5111
+  <name>QEMUGuest1</name>
3e5111
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
3e5111
+  <memory unit='KiB'>219136</memory>
3e5111
+  <currentMemory unit='KiB'>219136</currentMemory>
3e5111
+  <vcpu placement='static'>1</vcpu>
3e5111
+  <os>
3e5111
+    <type arch='i686' machine='pc'>hvm</type>
3e5111
+    <boot dev='hd'/>
3e5111
+  </os>
3e5111
+  <devices>
3e5111
+    <emulator>/usr/bin/qemu-system-i686</emulator>
3e5111
+    <controller type='usb' index='0'/>
3e5111
+    <memballoon model='virtio'/>
3e5111
+    <input type='mouse' bus='usb'>
3e5111
+      <address type='usb' bus='0'/>
3e5111
+    </input>
3e5111
+    <hub type='usb'>
3e5111
+      <address type='usb' bus='1'/>
3e5111
+    </hub>
3e5111
+  </devices>
3e5111
+</domain>
3e5111
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
3e5111
index cfd6dcd55..94be771d3 100644
3e5111
--- a/tests/qemuxml2argvtest.c
3e5111
+++ b/tests/qemuxml2argvtest.c
3e5111
@@ -1349,6 +1349,9 @@ mymain(void)
3e5111
     DO_TEST("usb-port-missing",
3e5111
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
3e5111
             QEMU_CAPS_NODEFCONFIG);
3e5111
+    DO_TEST_PARSE_ERROR("usb-bus-missing",
3e5111
+                        QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
3e5111
+                        QEMU_CAPS_NODEFCONFIG);
3e5111
     DO_TEST("usb-ports",
3e5111
             QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB,
3e5111
             QEMU_CAPS_NODEFCONFIG);
3e5111
-- 
3e5111
2.12.2
3e5111