[libmultipath] Fix segfault, when the syfs attribute doesn't exist
authorChristophe Varoqui <cvaroqui@zezette.localdomain>
Thu, 7 Jun 2007 20:39:45 +0000 (22:39 +0200)
committerChristophe Varoqui <cvaroqui@zezette.localdomain>
Thu, 7 Jun 2007 20:39:45 +0000 (22:39 +0200)
open '/class/fc_transport/target7:0:0'/'node_name'
new uncached attribute '/sys/class/fc_transport/target7:0:0/node_name'
add to cache '/sys/class/fc_transport/target7:0:0/node_name'
stat '/sys/class/fc_transport/target7:0:0/node_name' failed: No such file or directory

This would allocate no space for attr->value but and the next lookup tries to
dereference a NULL pointer.

Signed-off-by: Guido Guenther <agx@sigxcpu.org>
libmultipath/sysfs.c

index 0983e15..1fb5436 100644 (file)
@@ -317,7 +317,7 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
        const char *path;
        char value[NAME_SIZE];
        struct sysfs_attr *attr_loop;
-       struct sysfs_attr *attr;
+       struct sysfs_attr *attr = NULL;
        struct stat statbuf;
        int fd;
        ssize_t size;
@@ -349,7 +349,8 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
                list_add(&attr->node, &attr_list);
        } else {
                /* clear old value */
-               memset(attr->value, 0x00, sizeof(attr->value));
+               if(attr->value)
+                       memset(attr->value, 0x00, sizeof(attr->value));
        }
 
        if (lstat(path_full, &statbuf) != 0) {