vfio/pci: Handle subsystem realpath() returning NULL
authorAlex Williamson <alex.williamson@redhat.com>
Thu, 23 Aug 2018 16:45:57 +0000 (10:45 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 23 Aug 2018 16:45:57 +0000 (10:45 -0600)
Fix error reported by Coverity where realpath can return NULL,
resulting in a segfault in strcmp().  This should never happen given
that we're working through regularly structured sysfs paths, but
trivial enough to easily avoid.

Fixes: 238e91728503 ("vfio/ccw/pci: Allow devices to opt-in for ballooning")
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
hw/vfio/pci.c

index 056f3a887a8f5edbd7c9c8e55194fd31f643e9e5..866f0deeb7eb78a4da389bc33abd9bf6c4cdd145 100644 (file)
@@ -2879,7 +2879,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
     tmp = g_strdup_printf("%s/subsystem", vdev->vbasedev.sysfsdev);
     subsys = realpath(tmp, NULL);
     g_free(tmp);
-    is_mdev = (strcmp(subsys, "/sys/bus/mdev") == 0);
+    is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
     free(subsys);
 
     trace_vfio_mdev(vdev->vbasedev.name, is_mdev);