1 Star 0 Fork 21

Jingwiw/dmidecode

forked from src-openEuler/dmidecode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dmidecode-Do-not-let-dump-bin-overwrite-an-existing-.patch 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
Ni Cunshu 提交于 2023-04-18 09:45 +08:00 . fix CVE-2023-30630
From 6ca381c1247c81f74e1ca4e7706f70bdda72e6f2 Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 20 Feb 2023 14:53:31 +0100
Subject: [PATCH] dmidecode: Do not let --dump-bin overwrite an existing file
Make sure that the file passed to option --dump-bin does not already
exist. In practice, it is rather unlikely that an honest user would
want to overwrite an existing dump file, while this possibility
could be used by a rogue user to corrupt a system file.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
---
dmidecode.c | 14 ++++++++++++--
man/dmidecode.8 | 3 ++-
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/dmidecode.c b/dmidecode.c
index 6e7be63..82efa2d 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -60,6 +60,7 @@
* https://www.dmtf.org/sites/default/files/DSP0270_1.0.1.pdf
*/
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
@@ -5412,13 +5413,22 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
static int dmi_table_dump(const u8 *ep, u32 ep_len, const u8 *table,
u32 table_len)
{
+ int fd;
FILE *f;
- f = fopen(opt.dumpfile, "wb");
+ fd = open(opt.dumpfile, O_WRONLY|O_CREAT|O_EXCL, 0666);
+ if (fd == -1)
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("open");
+ return -1;
+ }
+
+ f = fdopen(fd, "wb");
if (!f)
{
fprintf(stderr, "%s: ", opt.dumpfile);
- perror("fopen");
+ perror("fdopen");
return -1;
}
diff --git a/man/dmidecode.8 b/man/dmidecode.8
index 62aa304..83affc2 100644
--- a/man/dmidecode.8
+++ b/man/dmidecode.8
@@ -1,4 +1,4 @@
-.TH DMIDECODE 8 "January 2019" "dmidecode"
+.TH DMIDECODE 8 "February 2023" "dmidecode"
.\"
.SH NAME
dmidecode \- \s-1DMI\s0 table decoder
@@ -164,6 +164,7 @@ hexadecimal and \s-1ASCII\s0. This option is mainly useful for debugging.
Do not decode the entries, instead dump the DMI data to a file in binary
form. The generated file is suitable to pass to \fB--from-dump\fP
later.
+\fIFILE\fP must not exist.
.TP
.BR " " " " "--from-dump \fIFILE\fP"
Read the DMI data from a binary file previously generated using
--
2.28.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Jingwiw/dmidecode.git
git@gitee.com:Jingwiw/dmidecode.git
Jingwiw
dmidecode
dmidecode
master

搜索帮助