[dm-devel] [PATCH 3/5] libmultipath: Zero-terminate sysfs_attr_get_value() result

Bart Van Assche bvanassche at acm.org
Fri Jul 18 12:53:39 UTC 2014


The callers of sysfs_attr_get_value() expect a '\0'-terminated string.
Hence terminate the string returned by this function with '\0'. Detected
by Valgrind.

Signed-off-by: Bart Van Assche <bvanassche at acm.org>
---
 libmultipath/sysfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index e5834f9..f42cda8 100644
--- a/libmultipath/sysfs.c
+++ b/libmultipath/sysfs.c
@@ -88,6 +88,8 @@ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
 	} else if (size == value_len) {
 		condlog(4, "overflow while reading from %s", devpath);
 		size = 0;
+	} else {
+		value[size] = '\0';
 	}
 
 	close(fd);
-- 
1.8.4.5




More information about the dm-devel mailing list