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

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