Fix sysfs_attr_get_value()
authorHannes Reinecke <hare@suse.de>
Wed, 7 Jan 2009 09:52:25 +0000 (10:52 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 21 Apr 2009 23:16:00 +0000 (01:16 +0200)
sysfs_attr_get_value() should return NULL if the attribute was not
found or found to be empty. And we should increase the attribute
value size to avoid overflows.
And overflows should be truncated, not ignored.

References: bnc#456747

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/structs.h
libmultipath/sysfs.c

index eb21ab21a910fb7ccc389b43e74c706c3df62cef..d7c3c88c227ffd9d709a4d0ae5cbc0b7e296e17d 100644 (file)
@@ -10,7 +10,7 @@
 #define CALLOUT_MAX_SIZE       128
 #define BLK_DEV_SIZE           33
 #define PATH_SIZE              512
-#define NAME_SIZE              128
+#define NAME_SIZE              512
 
 
 #define SCSI_VENDOR_SIZE       9
index c0d4d5fc468175905c98eb1f6e9a0247fe69c840..e00a101b5a5fca3126b324a1f11e240a733696dc 100644 (file)
@@ -445,8 +445,10 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
        close(fd);
        if (size < 0)
                goto out;
-       if (size == sizeof(value))
-               goto out;
+       if (size == sizeof(value)) {
+               dbg("overflow in attribute '%s', truncating", path_full);
+               size--;
+       }
 
        /* got a valid value, store and return it */
        value[size] = '\0';
@@ -456,7 +458,7 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
        attr->value = attr->value_local;
 
 out:
-       return attr->value;
+       return attr && attr->value && strlen(attr->value) ? attr->value : NULL;
 }
 
 int sysfs_lookup_devpath_by_subsys_id(char *devpath_full, size_t len,