Blame SOURCES/0029-Monitor-use-devname-as-char-array-instead-of-pointer.patch

b33395
From c8d1c398505b62d9129a4e711f17e4469f4327ff Mon Sep 17 00:00:00 2001
b33395
From: Kinga Tanska <kinga.tanska@intel.com>
b33395
Date: Thu, 14 Jul 2022 09:02:10 +0200
b33395
Subject: [PATCH 29/52] Monitor: use devname as char array instead of pointer
b33395
b33395
Device name wasn't filled properly due to incorrect use of strcpy.
b33395
Strcpy was used twice. Firstly to fill devname with "/dev/md/"
b33395
and then to add chosen name. First strcpy result was overwritten by
b33395
second one (as a result <device_name> instead of "/dev/md/<device_name>"
b33395
was assigned). This commit changes this implementation to use snprintf
b33395
and devname with fixed size.
b33395
b33395
Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
b33395
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
b33395
---
b33395
 Monitor.c | 8 +++++---
b33395
 1 file changed, 5 insertions(+), 3 deletions(-)
b33395
b33395
diff --git a/Monitor.c b/Monitor.c
b33395
index 6ca1ebe5..a5b11ae2 100644
b33395
--- a/Monitor.c
b33395
+++ b/Monitor.c
b33395
@@ -190,9 +190,11 @@ int Monitor(struct mddev_dev *devlist,
b33395
 			if (mdlist->devname[0] == '/')
b33395
 				st->devname = xstrdup(mdlist->devname);
b33395
 			else {
b33395
-				st->devname = xmalloc(8+strlen(mdlist->devname)+1);
b33395
-				strcpy(strcpy(st->devname, "/dev/md/"),
b33395
-				       mdlist->devname);
b33395
+				/* length of "/dev/md/" + device name + terminating byte */
b33395
+				size_t _len = sizeof("/dev/md/") + strnlen(mdlist->devname, PATH_MAX);
b33395
+
b33395
+				st->devname = xcalloc(_len, sizeof(char));
b33395
+				snprintf(st->devname, _len, "/dev/md/%s", mdlist->devname);
b33395
 			}
b33395
 			if (!is_mddev(mdlist->devname))
b33395
 				return 1;
b33395
-- 
b33395
2.31.1
b33395