libmultipath: Fix overflow in sysfs_get_str()
authorHannes Reinecke <hare@suse.de>
Tue, 17 Dec 2013 07:04:08 +0000 (08:04 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Tue, 17 Dec 2013 21:32:12 +0000 (22:32 +0100)
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

index b7470f8..228ffd3 100644 (file)
@@ -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);