[dm-devel] [PATCH 32/39] libmultipath/sysfs.c: always terminate value from sysfs_attr_get_value()

Hannes Reinecke hare at suse.de
Thu Jun 16 09:47:38 UTC 2016


Coverity complained that the returned value is not always NULL
terminated.

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

diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c
index a74de9f..2c0b591 100644
--- a/libmultipath/sysfs.c
+++ b/libmultipath/sysfs.c
@@ -86,16 +86,17 @@ ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
 	if (size < 0) {
 		condlog(4, "read from %s failed: %s", devpath, strerror(errno));
 		size = -errno;
+		value[0] = '\0';
 	} else if (size == value_len) {
+		value[size - 1] = '\0';
 		condlog(4, "overflow while reading from %s", devpath);
 		size = 0;
 	} else {
 		value[size] = '\0';
+		size = strchop(value);
 	}
 
 	close(fd);
-	if (size > 0)
-		size = strchop(value);
 	return size;
 }
 
-- 
2.6.6




More information about the dm-devel mailing list