1 Star 0 Fork 71

clcl/coreutils

forked from src-openEuler/coreutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-dd-do-not-access-uninitialized.patch 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
panxiaohe 提交于 2022-03-29 18:50 . backport patches from upstream
From 604f8a6c4d58a646c8722fdf7cad9ee67479d8f7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 31 Jan 2022 10:20:21 -0800
Subject: [PATCH] dd: do not access uninitialized
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* src/dd.c (parse_integer): Avoid undefined behavior
that accesses an uninitialized ‘n’ when e == LONGINT_INVALID.
Return more-accurate error code when INTMAX_MAX < n.
---
src/dd.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/dd.c b/src/dd.c
index e55f87f149..7360a49738 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1427,8 +1427,10 @@ static intmax_t
parse_integer (char const *str, strtol_error *invalid)
{
/* Call xstrtoumax, not xstrtoimax, since we don't want to
- allow strings like " -0". */
- uintmax_t n;
+ allow strings like " -0". Initialize N to an interminate value;
+ calling code should not rely on this function returning 0
+ when *INVALID represents a non-overflow error. */
+ uintmax_t n = 0;
char *suffix;
strtol_error e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0");
@@ -1468,7 +1470,7 @@ parse_integer (char const *str, strtol_error *invalid)
if (INTMAX_MAX < n)
{
- *invalid = LONGINT_OVERFLOW;
+ *invalid = e | LONGINT_OVERFLOW;
return INTMAX_MAX;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wd40/coreutils.git
git@gitee.com:wd40/coreutils.git
wd40
coreutils
coreutils
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385