[libvirt] [PATCH] pci: fix null pointer dereference

Clang detected a null-pointer dereference regression, introduced in commit 4e8969eb. Without this patch, a device with unbind_from_stub set to false would eventually try to call virFileExists on uncomputed drvdir. * src/util/pci.c (pciUnbindDeviceFromStub): Ensure drvdir is set before use. --- src/util/pci.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util/pci.c b/src/util/pci.c index 945f32a..d7f74f9 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -879,15 +879,16 @@ pciUnbindDeviceFromStub(pciDevice *dev, const char *driver) char *drvdir = NULL; char *path = NULL; + if (pciDriverDir(&drvdir, driver) < 0) + goto cleanup; + if (!dev->unbind_from_stub) goto remove_slot; /* If the device is bound to stub, unbind it. */ - if (pciDriverDir(&drvdir, driver) < 0 || - pciDeviceFile(&path, dev->name, "driver") < 0) { + if (pciDeviceFile(&path, dev->name, "driver") < 0) goto cleanup; - } if (virFileExists(drvdir) && virFileLinkPointsTo(path, drvdir)) { if (pciDriverFile(&path, driver, "unbind") < 0) { -- 1.7.4.4

On Tue, May 03, 2011 at 09:34:11AM -0600, Eric Blake wrote:
Clang detected a null-pointer dereference regression, introduced in commit 4e8969eb. Without this patch, a device with unbind_from_stub set to false would eventually try to call virFileExists on uncomputed drvdir.
* src/util/pci.c (pciUnbindDeviceFromStub): Ensure drvdir is set before use. --- src/util/pci.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/util/pci.c b/src/util/pci.c index 945f32a..d7f74f9 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -879,15 +879,16 @@ pciUnbindDeviceFromStub(pciDevice *dev, const char *driver) char *drvdir = NULL; char *path = NULL;
+ if (pciDriverDir(&drvdir, driver) < 0) + goto cleanup; + if (!dev->unbind_from_stub) goto remove_slot;
/* If the device is bound to stub, unbind it. */ - if (pciDriverDir(&drvdir, driver) < 0 || - pciDeviceFile(&path, dev->name, "driver") < 0) { + if (pciDeviceFile(&path, dev->name, "driver") < 0) goto cleanup; - }
if (virFileExists(drvdir) && virFileLinkPointsTo(path, drvdir)) { if (pciDriverFile(&path, driver, "unbind") < 0) {
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 05/03/2011 10:48 AM, Daniel P. Berrange wrote:
On Tue, May 03, 2011 at 09:34:11AM -0600, Eric Blake wrote:
Clang detected a null-pointer dereference regression, introduced in commit 4e8969eb. Without this patch, a device with unbind_from_stub set to false would eventually try to call virFileExists on uncomputed drvdir.
* src/util/pci.c (pciUnbindDeviceFromStub): Ensure drvdir is set before use. --- src/util/pci.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
ACK
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake