[dm-devel] [PATCH 10/72] libmultipath: allocate_binding(): detect line overflow

Martin Wilck Martin.Wilck at suse.com
Sat Oct 12 21:27:49 UTC 2019


From: Martin Wilck <mwilck at suse.com>

Be sure not to truncate the WWID. This shouldn't happen under
normal circumstances, but play it safe.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 libmultipath/alias.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index 2df34f32..15bbc8ed 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -244,7 +244,10 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix)
 		return NULL;
 
 	c = buf + i;
-	snprintf(c, LINE_MAX - i, " %s\n", wwid);
+	if (snprintf(c, LINE_MAX - i, " %s\n", wwid) >= LINE_MAX - i) {
+		condlog(1, "%s: line too long for %s\n", __func__, wwid);
+		return NULL;
+	}
 	buf[LINE_MAX - 1] = '\0';
 
 	offset = lseek(fd, 0, SEEK_END);
-- 
2.23.0





More information about the dm-devel mailing list