From 7a807e50f62f045b13a5b6e28ee02e36e42ad201 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Mon, 3 Dec 2018 22:02:00 +0000 Subject: [PATCH 14/16] vfio/pci: Handle subsystem realpath() returning NULL RH-Author: Alex Williamson Message-id: <154387452062.27651.8506633913988228901.stgit@gimli.home> Patchwork-id: 83239 O-Subject: [RHEL-8.0 qemu-kvm PATCH 5/7] vfio/pci: Handle subsystem realpath() returning NULL Bugzilla: 1650272 RH-Acked-by: Peter Xu RH-Acked-by: Auger Eric RH-Acked-by: Cornelia Huck RH-Acked-by: David Hildenbrand Bugzilla: 1650272 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 (cherry picked from commit a1c0f886496cfb4c336f8eb4155ed424567d653e) Signed-off-by: Danilo C. L. de Paula --- hw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d43727f..b463661 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2890,7 +2890,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); -- 1.8.3.1