[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 2/2] node_device: avoid null dereference on error



On 05/04/2011 07:37 PM, Eric Blake wrote:
If we plow on after udev_device_get_syspath fails, we will hit a NULL
dereference.  Clang found one due to strdup later in udevSetParent,
but in fact we hit a NULL dereference sooner because of the use of
STREQ within virNodeDeviceFindBySysfsPath.

* src/conf/node_device_conf.h (virNodeDeviceFindBySysfsPath): Mark
path argument non-null.
* src/node_device/node_device_udev.c (udevSetParent): Avoid null
dereference.
---
  src/conf/node_device_conf.h        |    5 +++--
  src/node_device/node_device_udev.c |    6 ++++--
  2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 975abb3..e90bdc5 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -1,7 +1,7 @@
  /*
   * node_device_conf.h: config handling for node devices
   *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
   * Copyright (C) 2008 Virtual Iron Software, Inc.
   * Copyright (C) 2008 David F. Lively
   *
@@ -228,7 +228,8 @@ virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs,
                                              const char *name);
  virNodeDeviceObjPtr
  virNodeDeviceFindBySysfsPath(const virNodeDeviceObjListPtr devs,
-                             const char *sysfs_path);
+                             const char *sysfs_path)
+    ATTRIBUTE_NONNULL(2);

  virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs,
                                             const virNodeDeviceDefPtr def);
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 8cf0e82..9cca375 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1236,8 +1236,10 @@ static int udevSetParent(struct udev_device *device,

          parent_sysfs_path = udev_device_get_syspath(parent_device);
          if (parent_sysfs_path == NULL) {
-            VIR_DEBUG("Could not get syspath for parent of '%s'",
-                      udev_device_get_syspath(parent_device));
+            virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
+                                     _("Could not get syspath for parent of '%s'"),
+                                     udev_device_get_syspath(parent_device));
+            goto out;
          }

          dev = virNodeDeviceFindBySysfsPath(&driverState->devs,

ACK.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]