From 913a0dbb3a493adb305fc17c7f283de0adca73c5 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sun, 4 Mar 2012 17:40:59 +0000 Subject: [PATCH] Validate udev structures Avoid using NULL pointers from udev. It seems like some older versions of udev were improperly returning NULL in some case, so do not silently break here, and give at least a warning to the user. --- WHATS_NEW | 2 +- WHATS_NEW_DM | 1 + lib/device/dev-cache.c | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index c61b19e08..893f9c3aa 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,6 +1,6 @@ Version 2.02.95 - ================================ - Deactivation of failed thin check on thin pool returns success. + Validate udev structures in _insert_udev_dir(). Scan all devices for lvmetad if 'pvscan --cache' used without device list. Populate lvmcache from lvmetad before displaying PVs in pvscan. (2.02.94) Suppress incorrect -n pvscan warning now always displayed. (2.02.94) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index a76b888bf..a4e90fb5c 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.74 - ================================ + Deactivation of failed thin check on thin pool returns success. Version 1.02.73 - 3rd March 2012 ================================ diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index a8dba87de..ce727baaa 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -509,14 +509,21 @@ static int _insert_udev_dir(struct udev *udev, const char *dir) goto bad; udev_list_entry_foreach(device_entry, udev_enumerate_get_list_entry(udev_enum)) { - device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(device_entry)); + if (!(device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(device_entry)))) { + log_warn("Udev returns NULL device."); + continue; + } - node_name = udev_device_get_devnode(device); - r &= _insert(node_name, 0, 0); + if (!(node_name = udev_device_get_devnode(device))) + log_warn("Udev returns NULL devnode."); + else + r &= _insert(node_name, 0, 0); udev_list_entry_foreach(symlink_entry, udev_device_get_devlinks_list_entry(device)) { - symlink_name = udev_list_entry_get_name(symlink_entry); - r &= _insert(symlink_name, 0, 0); + if (!(symlink_name = udev_list_entry_get_name(symlink_entry))) + log_warn("Udev returns NULL name."); + else + r &= _insert(symlink_name, 0, 0); } udev_device_unref(device);