diff mbox

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

Message ID 53C918D3.7060908@acm.org (mailing list archive)
State Not Applicable, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Bart Van Assche July 18, 2014, 12:53 p.m. UTC
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@acm.org>
---
 libmultipath/sysfs.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox

Patch

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);