1 Star 0 Fork 25

池鱼/util-linux

forked from src-anolis-os/util-linux 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0028-libmount-use-fmemopen-in-more-robust-way-coverity-sc.patch 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
张彬琛 提交于 2021-01-20 14:01 . import util-linux-2.32.1-22.el8.src.rpm
From d9fe56d8da9015694fcba5f3dd850becff677ab5 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Fri, 20 Sep 2019 13:00:19 +0200
Subject: [PATCH] libmount: use fmemopen() in more robust way [coverity scan]
Upstream: http://github.com/karelzak/util-linux/commit/026f7d302066a4e6f5a69dc9818ec3180939f4a3
Upstream: http://github.com/karelzak/util-linux/commit/bc747dfccf511419312ec872cefa90e25d83136a
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1751447
Signed-off-by: Karel Zak <kzak@redhat.com>
---
libmount/src/utils.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index f7d85d124..04e79f53f 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -1219,20 +1219,26 @@ success:
*/
FILE *mnt_get_procfs_memstream(int fd, char **membuf)
{
- FILE *memf;
size_t sz = 0;
off_t cur;
+ *membuf = NULL;
+
/* in case of error, rewind to the original position */
cur = lseek(fd, 0, SEEK_CUR);
- if (read_procfs_file(fd, membuf, &sz) == 0
- && sz > 0
- && (memf = fmemopen(*membuf, sz, "r")))
- return memf;
+ if (read_procfs_file(fd, membuf, &sz) == 0 && sz > 0) {
+ FILE *memf = fmemopen(*membuf, sz, "r");
+ if (memf)
+ return memf; /* success */
+
+ free(*membuf);
+ *membuf = NULL;
+ }
/* error */
- lseek(fd, cur, SEEK_SET);
+ if (cur != (off_t) -1)
+ lseek(fd, cur, SEEK_SET);
return NULL;
}
#else
--
2.21.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zxy19951122/util-linux.git
git@gitee.com:zxy19951122/util-linux.git
zxy19951122
util-linux
util-linux
a8

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385