All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libmultipath: Don't chop const strings
@ 2014-02-12 16:21 Benjamin Marzinski
  2014-02-13  7:43 ` Hannes Reinecke
  2014-02-13 21:22 ` Christophe Varoqui
  0 siblings, 2 replies; 3+ messages in thread
From: Benjamin Marzinski @ 2014-02-12 16:21 UTC (permalink / raw)
  To: device-mapper development; +Cc: Christophe Varoqui

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 <bmarzins@redhat.com>
---
 libmultipath/discovery.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 228ffd3..a6ff658 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-13 21:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-12 16:21 [PATCH] libmultipath: Don't chop const strings Benjamin Marzinski
2014-02-13  7:43 ` Hannes Reinecke
2014-02-13 21:22 ` Christophe Varoqui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.