[libvirt] [PATCH] udev_device_get_devpath might return NULL

Guido Günther agx at sigxcpu.org
Mon Dec 7 18:15:13 UTC 2009


Fix crash on daemon strdup in that case.

udev_device_get_devpath returs NULL for
'/sys/devices/virtual/block/dm-*' devices. In that case the later strdup
segfaults. O.k. to apply?

19:12:46.319: info : udevGetDeviceProperty:111 : udev reports device 'dm-0' does not have property 'DRIVER'
19:12:46.319: debug : udevProcessStorage:954 : No devnode for '/devices/virtual/block/dm-0'
19:12:46.319: info : udevProcessDeviceListEntry:1261 : Failed to create node device for udev device '/sys/devices/virtual/block/dm-0'

---
 src/node_device/node_device_udev.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 9b48052..c7238fc 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -947,8 +947,14 @@ static int udevProcessStorage(struct udev_device *device,
 {
     union _virNodeDevCapData *data = &def->caps->data;
     int ret = -1;
+    const char* devnode;
 
-    data->storage.block = strdup(udev_device_get_devnode(device));
+    devnode = udev_device_get_devnode(device);
+    if(!devnode) {
+        VIR_DEBUG("No devnode for '%s'\n", udev_device_get_devpath(device));
+        goto out;
+    }
+    data->storage.block = strdup(devnode);
     if (udevGetStringProperty(device,
                               "DEVNAME",
                               &data->storage.block) == PROPERTY_ERROR) {
-- 
1.6.5.3




More information about the libvir-list mailing list