Blame SOURCES/libvirt-qemu-do-not-crash-on-USB-address-with-no-port-and-invalid-bus.patch

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