From 37d54871a5d9c1225fe925247ffdc9a39ad286ab Mon Sep 17 00:00:00 2001 From: Eric Blake <eblake@redhat.com> Date: Fri, 28 Oct 2011 09:31:57 -0600 Subject: [PATCH] qemu: avoid leaking uninit data from hotplug to dumpxml To: libvir-list@redhat.com https://bugzilla.redhat.com/show_bug.cgi?id=747514 Detected by Coverity. The fix in 2c27dfa didn't catch all bad instances of memcpy(). Thankfully, on further analysis, all of the problematic uses are only triggered by old qemu that lacks -device. * src/qemu/qemu_hotplug.c (qemuDomainAttachPciDiskDevice) (qemuDomainAttachNetDevice, qemuDomainAttachHostPciDevice): Init all fields since monitor only populates some of them. (cherry picked from commit a4ca6e5d0f9f707b81f757eeac381144c8e0533c) Conflicts: src/qemu/qemu_hotplug.c - upstream split file from qemu_driver.c Signed-off-by: Daniel Veillard <veillard@redhat.com> --- src/qemu/qemu_driver.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2943681..b0ac1d4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7400,7 +7400,7 @@ static int qemudDomainAttachPciDiskDevice(struct qemud_driver *driver, } } } else { - virDomainDevicePCIAddress guestAddr; + virDomainDevicePCIAddress guestAddr = disk->info.addr.pci; ret = qemuMonitorAddPCIDisk(priv->mon, disk->src, type, @@ -7911,6 +7911,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, goto try_remove; } } else { + guestAddr = net->info.addr.pci; if (qemuMonitorAddPCINetwork(priv->mon, nicstr, &guestAddr) < 0) { qemuDomainObjExitMonitorWithDriver(driver, vm); @@ -8053,7 +8054,7 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver, ret = qemuMonitorAddDevice(priv->mon, devstr); qemuDomainObjExitMonitorWithDriver(driver, vm); } else { - virDomainDevicePCIAddress guestAddr; + virDomainDevicePCIAddress guestAddr = hostdev->info.addr.pci; qemuDomainObjEnterMonitorWithDriver(driver, vm); ret = qemuMonitorAddPCIHostDevice(priv->mon, -- 1.7.4.4