From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Marzinski Subject: [PATCH v2] multipath: check for NULL from udev_device_get_* Date: Thu, 10 Jan 2013 15:00:56 -0600 Message-ID: <20130110210056.GC19059@ether.msp.redhat.com> Reply-To: device-mapper development Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: device-mapper development Cc: Christophe Varoqui List-Id: dm-devel.ids The udev_device_get_* functions can return NULL, an occassionally do so in the multipathd code. multipath needs to check if the result is NULL before dereferencing it. Signed-off-by: Benjamin Marzinski --- libmultipath/discovery.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) Index: multipath-tools-120821/libmultipath/discovery.c =================================================================== --- multipath-tools-120821.orig/libmultipath/discovery.c +++ multipath-tools-120821/libmultipath/discovery.c @@ -113,6 +113,7 @@ path_discovery (vector pathvec, struct c udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(udev_iter)) { + const char *devtype; devpath = udev_list_entry_get_name(entry); condlog(4, "Discover device %s", devpath); udevice = udev_device_new_from_syspath(conf->udev, devpath); @@ -121,7 +122,8 @@ path_discovery (vector pathvec, struct c r++; continue; } - if(!strncmp(udev_device_get_devtype(udevice), "disk", 4)) + devtype = udev_device_get_devtype(udevice); + if(devtype && !strncmp(devtype, "disk", 4)) r += path_discover(pathvec, conf, udevice, flag); udev_device_unref(udevice); } @@ -459,7 +461,8 @@ scsi_sysfs_pathinfo (struct path * pp) parent = pp->udev; while (parent) { - if (!strncmp(udev_device_get_subsystem(parent), "scsi", 4)) { + const char *subsys = udev_device_get_subsystem(parent); + if (subsys && !strncmp(subsys, "scsi", 4)) { attr_path = udev_device_get_sysname(parent); if (!attr_path) break; @@ -525,7 +528,8 @@ ccw_sysfs_pathinfo (struct path * pp) parent = pp->udev; while (parent) { - if (!strncmp(udev_device_get_subsystem(parent), "ccw", 3)) + const char *subsys = udev_device_get_subsystem(parent); + if (subsys && !strncmp(subsys, "ccw", 3)) break; parent = udev_device_get_parent(parent); } @@ -581,7 +585,8 @@ cciss_sysfs_pathinfo (struct path * pp) parent = pp->udev; while (parent) { - if (!strncmp(udev_device_get_subsystem(parent), "cciss", 5)) { + const char *subsys = udev_device_get_subsystem(parent); + if (subsys && !strncmp(subsys, "cciss", 5)) { attr_path = udev_device_get_sysname(parent); if (!attr_path) break; @@ -662,7 +667,8 @@ path_offline (struct path * pp) parent = pp->udev; while (parent) { - if (!strncmp(udev_device_get_subsystem(parent), "scsi", 4)) + const char *subsys = udev_device_get_subsystem(parent); + if (subsys && !strncmp(subsys, "scsi", 4)) break; parent = udev_device_get_parent(parent); }