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>
#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
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';
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,