[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[dm-devel] [PATCH 5/5] libmultipath: Fix overflow in sysfs_get_str()



sysfs_get_str() should first do a strchop() before comparing the
returned string length with the provided buffer. Otherwise we might
incur a false positive as the overflowing bits might be occupied
by spaces, which will be removed later on.

Signed-off-by: Hannes Reinecke <hare suse de>
---
 libmultipath/discovery.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index b7470f8..228ffd3 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -157,13 +157,12 @@ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len)	\
 			devname, #fname);				\
 		return -ENXIO;						\
 	}								\
-	if (strlen(attr) > len) {					\
+	if (strchop(attr) > len) {					\
 		condlog(3, "%s: overflow in attribute %s",		\
 			devname, #fname);				\
 		return -EINVAL;						\
 	}								\
-	strlcpy(buff, attr, len);					\
-	return strchop(buff);						\
+	return strlcpy(buff, attr, len);				\
 }
 
 declare_sysfs_get_str(devtype);
-- 
1.7.12.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]