[libvirt] [PATCH] qemu: avoid dereferencing a NULL pointer

From: Alex Jia <ajia@redhat.com> * src/qemu/qemu_hostdev.c: function 'pciDeviceListFind' probably explicitly returns null, however, the function 'pciDeviceSetUsedBy' directly uses it without any judgement. Signed-off-by: Alex Jia <ajia@redhat.com> --- src/qemu/qemu_hostdev.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index c65f6f5..4e148b0 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -227,9 +227,8 @@ int qemuPrepareHostdevPCIDevices(struct qemud_driver *driver, pciDevice *dev, *activeDev; dev = pciDeviceListGet(pcidevs, i); - activeDev = pciDeviceListFind(driver->activePciHostdevs, dev); - - pciDeviceSetUsedBy(activeDev, name); + if ((activeDev = pciDeviceListFind(driver->activePciHostdevs, dev))) + pciDeviceSetUsedBy(activeDev, name); } /* Loop 6: Now steal all the devices from pcidevs */ -- 1.7.1

On 10/17/2011 10:09 AM, ajia@redhat.com wrote:
From: Alex Jia<ajia@redhat.com>
* src/qemu/qemu_hostdev.c: function 'pciDeviceListFind' probably explicitly returns null, however, the function 'pciDeviceSetUsedBy' directly uses it without any judgement.
Signed-off-by: Alex Jia<ajia@redhat.com> --- src/qemu/qemu_hostdev.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index c65f6f5..4e148b0 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -227,9 +227,8 @@ int qemuPrepareHostdevPCIDevices(struct qemud_driver *driver, pciDevice *dev, *activeDev;
dev = pciDeviceListGet(pcidevs, i); - activeDev = pciDeviceListFind(driver->activePciHostdevs, dev); - - pciDeviceSetUsedBy(activeDev, name); + if ((activeDev = pciDeviceListFind(driver->activePciHostdevs, dev))) + pciDeviceSetUsedBy(activeDev, name);
False positive. Just a few lines earlier, in loop 4, we guaranteed that dev was added to driver->activePciHostdevs, therefore, activeDev cannot be NULL here. That said, we could probably simplify things by consolidating loop 5 and 6 into one, and in the process of that simplification, silence the spurious warning from the static analyzer. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

----- Original Message ----- From: "Eric Blake" <eblake@redhat.com> False positive. Just a few lines earlier, in loop 4, we guaranteed that dev was added to driver->activePciHostdevs, therefore, activeDev cannot be NULL here. That said, we could probably simplify things by consolidating loop 5 and 6 into one, and in the process of that simplification, silence the
it should consolidate loop 4 and loop 5 into one :-)however, loop 6 steps are a clear design if don't consider Coverity complains.
Alex spurious warning from the static analyzer. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (3)
-
ajia@redhat.com
-
Alex Jia
-
Eric Blake