libmultipath: Don't chop const strings
Benjamin Marzinski
maintainerPATCH 1/1 libmultipath: Don't chop const strings
multipath was chopping sysfs attr strings in order to make sure that ending whitespace didn't cause them to overflow their buffer. However those strings were const strings. This patch makes multipath check how much of the string length is ending whitespace, so that it can tell if it will really overflow the buffer without chopping the const string.
--- libmultipath/discovery.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
libmultipath/discovery.c +6 -2
@@ -4,6 +4,7 @@* Copyright (c) 2005 Mike Anderson */ #include <stdio.h> +#include <ctype.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h>
@@ -143,6 +144,7 @@ path_discovery (vector pathvec, struct config * conf, int flag)extern ssize_t \ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ { \ +int l; \const char * attr; \const char * devname; \ \
@@ -157,12 +159,14 @@ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ devname, #fname); \ return -ENXIO; \ } \ - if (strchop(attr) > len) { \ + for (l = strlen(attr); l >= 1 && isspace(attr[l-1]); l--); \ + if (l > len) { \ condlog(3, "%s: overflow in attribute %s", \ devname, #fname); \ return -EINVAL; \ } \ - return strlcpy(buff, attr, len); \ + strlcpy(buff, attr, len); \ + return strchop(buff); \ }declare_sysfs_get_str (devtype);
Signature · 1 line
1.8.4.2
Quoted 7 lines · Benjamin Marzinski
multipath was chopping sysfs attr strings in order to make sure that ending whitespace didn't cause them to overflow their buffer. However those strings were const strings. This patch makes multipath check how much of the string length is ending whitespace, so that it can tell if it will really overflow the buffer without chopping the const string.
Signed-off-by Benjamin Marzinski <[email protected]>
Yeah, you are correct.
I actually have a similar patch, but didn't manage to send it upstream.
So:
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Christophe Varoqui
AppliedApplied,
thanks.
Quoted 55 lines · Benjamin Marzinski
multipath was chopping sysfs attr strings in order to make sure that ending whitespace didn't cause them to overflow their buffer. However those strings were const strings. This patch makes multipath check how much of the string length is ending whitespace, so that it can tell if it will really overflow the buffer without chopping the const string.
Signed-off-by Benjamin Marzinski <[email protected]>--- libmultipath/discovery.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)libmultipath/discovery.c +6
-3@@ -4,6 +4,7 @@* Copyright (c) 2005 Mike Anderson */ #include <stdio.h> +#include <ctype.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> @@ -143,6 +144,7 @@ path_discovery (vector pathvec, struct config * conf, int flag)extern ssize_t \ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ { \ +int l; \const char * attr; \const char * devname; \ \@@ -157,12 +159,14 @@ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ devname, #fname); \ return -ENXIO; \ } \ - if (strchop(attr) > len) { \ + for (l = strlen(attr); l >= 1 && isspace(attr[l-1]); l--); \ + if (l > len) { \ condlog(3, "%s: overflow in attribute %s", \ devname, #fname); \ return -EINVAL; \ } \ - return strlcpy(buff, attr, len); \ + strlcpy(buff, attr, len); \ + return strchop(buff); \ }declare_sysfs_get_str (devtype); --1.8.4.2
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel