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

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

 



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

Signed-off-by: Hannes Reinecke <hare@xxxxxxxx>
---
 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

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel



[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux