diff mbox series

[v2,3/4] util: Fix for NULL dereference

Message ID 20181117195113.12544-4-radoslaw.biernacki@linaro.org
State Accepted
Commit 8fac64db5e7941efb820626f0043f5e0a31c79ee
Headers show
Series util: Fixing libvirt errors on cavium/thunder-nicvf | expand

Commit Message

Radoslaw Biernacki Nov. 17, 2018, 7:51 p.m. UTC
The device xml parser code does not set "model" while parsing
<interface type='hostdev'>
  <source>
    <address type='pci' domain='0x0002' bus='0x01' slot='0x00' function='0x2'/>
  </source>
</interface>
virDomainDefPtr def->nets[i]->model can be NULL while latter compares strings with
STREQ instead of STREQ_NULLABLE.

Fixes: ac47e4a6225 (qemu: replace "def->nets[i]" with "net" and "def->sounds[i]" with "sound")
Fixes: c7fc151eec7 (qemu: assign virtio devices to PCIe slot when appropriate)
Signed-off-by: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

---
 src/qemu/qemu_domain_address.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 73ed9cc68c..f9275ed810 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -232,10 +232,8 @@  qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
 
-        if (net->model &&
-            STREQ(net->model, "spapr-vlan")) {
+        if (STREQ_NULLABLE(net->model, "spapr-vlan"))
             net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
-        }
 
         if (qemuDomainAssignSpaprVIOAddress(def, &net->info, VIO_ADDR_NET) < 0)
             goto cleanup;
@@ -324,8 +322,7 @@  qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
 
-        if (net->model &&
-            STREQ(net->model, "virtio") &&
+        if (STREQ_NULLABLE(net->model, "virtio") &&
             net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
             net->info.type = type;
         }
@@ -692,14 +689,14 @@  qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
          * addresses for other hostdev devices.
          */
         if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||
-            STREQ(net->model, "usb-net")) {
+            STREQ_NULLABLE(net->model, "usb-net")) {
             return 0;
         }
 
-        if (STREQ(net->model, "virtio"))
+        if (STREQ_NULLABLE(net->model, "virtio"))
             return  virtioFlags;
 
-        if (STREQ(net->model, "e1000e"))
+        if (STREQ_NULLABLE(net->model, "e1000e"))
             return pcieFlags;
 
         return pciFlags;