15 Star 2 Fork 56

src-openEuler/util-linux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-more-avoid-out-of-bound-access.patch 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
zhangyao2022 提交于 2024-11-15 16:22 . sync patches from the old version
From ecdfc9aa701b4f406c239b6e163a45a5cc5b4a8c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Fri, 22 Sep 2023 19:53:24 +0200
Subject: [PATCH] more: avoid out-of-bound access
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The realloc() needs to happen before that memory is used.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
Reference:https://github.com/util-linux/util-linux/commit/ecdfc9aa701b4f406c239b6e163a45a5cc5b4a8c
Conflict:NA
---
text-utils/more.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/text-utils/more.c b/text-utils/more.c
index bdb34e076..e25b0e24c 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -356,11 +356,11 @@ static void env_argscan(struct more_control *ctl, const char *s)
env_argv = xmalloc(sizeof(char *) * size);
env_argv[0] = _("MORE environment variable"); /* program name */
for (tok = strtok_r(str, delim, &key); tok; tok = strtok_r(NULL, delim, &key)) {
- env_argv[env_argc++] = tok;
- if (size < env_argc) {
+ if (size == env_argc) {
size *= 2;
env_argv = xrealloc(env_argv, sizeof(char *) * size);
}
+ env_argv[env_argc++] = tok;
}
argscan(ctl, env_argc, env_argv);
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/util-linux.git
git@gitee.com:src-openeuler/util-linux.git
src-openeuler
util-linux
util-linux
master

搜索帮助