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

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