From e9c00f47ab399a0f77929fce0ae020a2de688021 Mon Sep 17 00:00:00 2001 From: Eric Blake <eblake@redhat.com> Date: Mon, 18 Jun 2012 16:30:18 -0600 Subject: [PATCH] node_device: avoid null dereference on error To: libvir-list@redhat.com 5.9: https://bugzilla.redhat.com/show_bug.cgi?id=772848 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. (cherry picked from commit 98cd17bd18a78996243f712ece5bc00649dc427f) Conflicts: src/node_device/node_device_udev.c - inline one hunk of 7a4bc156 Signed-off-by: Daniel Veillard <veillard@redhat.com> --- 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 fe0f2bf..7723091 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 02e44a1..f50518d 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_INFO("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, -- 1.7.7.4