mdadm/6017-Monitor-use-devname-as-char-array-instead-of-pointer.patch
Zhiqiang Liu 5ee6fbf059 backport four bugfix patches
fix issue:https://gitee.com/src-openeuler/mdadm/issues/I62L1B?from=project-issue

Signed-off-by: liuzhiqiang <lzhq28@mail.ustc.edu.cn>
(cherry picked from commit 304fa34fea4c4543d0c07bd9ab14abffcf45a8bb)
2023-01-06 15:59:53 +08:00

44 lines
1.6 KiB
Diff

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