]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: fix segfault when detaching non-existent network device
authorGuannan Ren <gren@redhat.com>
Mon, 12 Mar 2012 15:50:02 +0000 (23:50 +0800)
committerLaine Stump <laine@laine.org>
Tue, 13 Mar 2012 07:06:35 +0000 (03:06 -0400)
In qemuDomainDetachNetDevice, detach was being used before it had been
validated. If no matching device was found, this resulted in a
dereference of a NULL pointer.

This behavior was a regression introduced in commit
cf90342be0022520e25cfa258cef1034b229a100, so it has not been a part of
any official libvirt release.

src/qemu/qemu_hotplug.c

index 1e563545b6f91a10283c0eedf90792803fa6d19a..e088a49121d48a06208ed04fae199bebcd2488d8 100644 (file)
@@ -2081,13 +2081,6 @@ qemuDomainDetachNetDevice(struct qemud_driver *driver,
         }
     }
 
-    if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
-        ret = qemuDomainDetachThisHostDevice(driver, vm,
-                                             virDomainNetGetActualHostdev(detach),
-                                             -1);
-        goto cleanup;
-    }
-
     if (!detach) {
         qemuReportError(VIR_ERR_OPERATION_FAILED,
                         _("network device %02x:%02x:%02x:%02x:%02x:%02x not found"),
@@ -2097,6 +2090,13 @@ qemuDomainDetachNetDevice(struct qemud_driver *driver,
         goto cleanup;
     }
 
+    if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+        ret = qemuDomainDetachThisHostDevice(driver, vm,
+                                             virDomainNetGetActualHostdev(detach),
+                                             -1);
+        goto cleanup;
+    }
+
     if (!virDomainDeviceAddressIsValid(&detach->info,
                                        VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
         qemuReportError(VIR_ERR_OPERATION_FAILED,