加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0024-mdadm-Monitor.c-fix-coverity-issues.patch 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
wguanghao 提交于 2024-08-26 15:49 . backport bugfix patches from community
From 4e9e7cc59fab61e16a93d0ae3b73e9b9b0001d4b Mon Sep 17 00:00:00 2001
From: Nigel Croxon <ncroxon@redhat.com>
Date: Mon, 15 Jul 2024 10:13:46 -0400
Subject: [PATCH] mdadm: Monitor.c fix coverity issues
Fixing the following coding errors the coverity tools found:
* Event check_return: Calling "fcntl(fd, 2, 1)" without checking
return value. This library function may fail and return an error code.
* Dereferencing "sl", which is known to be "NULL".
* Event fixed_size_dest: You might overrun the 32-character fixed-size
string "devnm" by copying "tmp" without checking the length.
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
---
Monitor.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/Monitor.c b/Monitor.c
index 9f1765d..4637729 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -570,7 +570,9 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
if (!is_container && !md_array_active(fd))
goto disappeared;
- fcntl(fd, F_SETFD, FD_CLOEXEC);
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ goto out;
+
if (md_get_array_info(fd, &array) < 0)
goto disappeared;
@@ -796,7 +798,8 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
strcpy(st->parent_devnm,
mse->metadata_version+10);
sl = strchr(st->parent_devnm, '/');
- *sl = 0;
+ if (sl)
+ *sl = 0;
} else
st->parent_devnm[0] = 0;
*statelist = st;
@@ -1135,7 +1138,7 @@ int Wait(char *dev)
return 2;
}
- strcpy(devnm, tmp);
+ snprintf(devnm, sizeof(devnm), "%s", tmp);
while(1) {
struct mdstat_ent *ms = mdstat_read(1, 0);
@@ -1206,7 +1209,8 @@ int WaitClean(char *dev, int verbose)
return 1;
}
- strcpy(devnm, fd2devnm(fd));
+ snprintf(devnm, sizeof(devnm), "%s", fd2devnm(fd));
+
mdi = sysfs_read(fd, devnm, GET_VERSION|GET_LEVEL|GET_SAFEMODE);
if (!mdi) {
if (verbose)
--
2.43.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化