Blame SOURCES/kvm-vfio-pci-Handle-subsystem-realpath-returning-NULL.patch

26ba25
From 7a807e50f62f045b13a5b6e28ee02e36e42ad201 Mon Sep 17 00:00:00 2001
26ba25
From: Alex Williamson <alex.williamson@redhat.com>
26ba25
Date: Mon, 3 Dec 2018 22:02:00 +0000
26ba25
Subject: [PATCH 14/16] vfio/pci: Handle subsystem realpath() returning NULL
26ba25
26ba25
RH-Author: Alex Williamson <alex.williamson@redhat.com>
26ba25
Message-id: <154387452062.27651.8506633913988228901.stgit@gimli.home>
26ba25
Patchwork-id: 83239
26ba25
O-Subject: [RHEL-8.0 qemu-kvm PATCH 5/7] vfio/pci: Handle subsystem realpath() returning NULL
26ba25
Bugzilla: 1650272
26ba25
RH-Acked-by: Peter Xu <peterx@redhat.com>
26ba25
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
26ba25
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
26ba25
RH-Acked-by: David Hildenbrand <david@redhat.com>
26ba25
26ba25
Bugzilla: 1650272
26ba25
26ba25
Fix error reported by Coverity where realpath can return NULL,
26ba25
resulting in a segfault in strcmp().  This should never happen given
26ba25
that we're working through regularly structured sysfs paths, but
26ba25
trivial enough to easily avoid.
26ba25
26ba25
Fixes: 238e91728503 ("vfio/ccw/pci: Allow devices to opt-in for ballooning")
26ba25
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
26ba25
(cherry picked from commit a1c0f886496cfb4c336f8eb4155ed424567d653e)
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 hw/vfio/pci.c | 2 +-
26ba25
 1 file changed, 1 insertion(+), 1 deletion(-)
26ba25
26ba25
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
26ba25
index d43727f..b463661 100644
26ba25
--- a/hw/vfio/pci.c
26ba25
+++ b/hw/vfio/pci.c
26ba25
@@ -2890,7 +2890,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
26ba25
     tmp = g_strdup_printf("%s/subsystem", vdev->vbasedev.sysfsdev);
26ba25
     subsys = realpath(tmp, NULL);
26ba25
     g_free(tmp);
26ba25
-    is_mdev = (strcmp(subsys, "/sys/bus/mdev") == 0);
26ba25
+    is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
26ba25
     free(subsys);
26ba25
 
26ba25
     trace_vfio_mdev(vdev->vbasedev.name, is_mdev);
26ba25
-- 
26ba25
1.8.3.1
26ba25