node_device: avoid null dereference on error

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.
This commit is contained in:
Eric Blake 2011-05-04 17:03:52 -06:00
parent 4c6ae9ae36
commit 98cd17bd18
2 changed files with 7 additions and 4 deletions

View File

@ -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);

View File

@ -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,