tests/libqos: Check for valid dev pointer when looking for PCI devices
authorThomas Huth <thuth@redhat.com>
Tue, 27 Feb 2018 06:44:44 +0000 (07:44 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Mon, 5 Mar 2018 09:03:17 +0000 (09:03 +0000)
dev could be NULL if the PCI device can not be found due to some
reasons, so we must not dereference the pointer in this case.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-id: 1519713884-2346-1-git-send-email-thuth@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
tests/libqos/virtio-pci.c

index 7ac15c04e17ea9660582da6d2536ac6cbb2ded36..550dede0a2e807038cfb00da2e0ee007edb17a28 100644 (file)
@@ -315,7 +315,9 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
     qvirtio_pci_foreach(bus, device_type, false, 0,
                         qvirtio_pci_assign_device, &dev);
 
-    dev->vdev.bus = &qvirtio_pci;
+    if (dev) {
+        dev->vdev.bus = &qvirtio_pci;
+    }
 
     return dev;
 }