61 lines
1.7 KiB
Plaintext
61 lines
1.7 KiB
Plaintext
From 67c3b7d8d0ec6f438d11c02c0ad78041ef67d924 Mon Sep 17 00:00:00 2001
|
|
From: Hannes Reinecke <hare@suse.de>
|
|
Date: Wed, 7 Jan 2009 10:52:25 +0100
|
|
Subject: [PATCH] Fix sysfs_attr_get_value()
|
|
|
|
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 | 2 +-
|
|
libmultipath/sysfs.c | 8 +++++---
|
|
2 files changed, 6 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
|
|
index 75bd379..8596e8d 100644
|
|
--- a/libmultipath/structs.h
|
|
+++ b/libmultipath/structs.h
|
|
@@ -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
|
|
diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
|
|
index c0d4d5f..e00a101 100644
|
|
--- a/libmultipath/sysfs.c
|
|
+++ b/libmultipath/sysfs.c
|
|
@@ -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,
|
|
--
|
|
1.6.0.2
|
|
|