1 Star 0 Fork 44

A-Znk/less

forked from src-openEuler/less 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Some-constifying.patch 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
wjiang 提交于 2024-04-22 14:29 . fix CVE-2024-32487
From 756acc92c9d6bea9929d9105207e081054be05fb Mon Sep 17 00:00:00 2001
From: Mark Nudelman <[email protected]>
Date: Mon, 6 Nov 2023 11:44:08 -0800
Subject: [PATCH] Some constifying.
---
filename.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/filename.c b/filename.c
index a8726dc..672dc94 100644
--- a/filename.c
+++ b/filename.c
@@ -136,12 +136,13 @@ static int metachar(char c)
/*
* Insert a backslash before each metacharacter in a string.
*/
-public char * shell_quote(char *s)
+public char * shell_quote(constant char *s)
{
- char *p;
+ constant char *p;
+ char *np;
char *newstr;
int len;
- char *esc = get_meta_escape();
+ constant char *esc = get_meta_escape();
int esclen = (int) strlen(esc);
int use_quotes = 0;
int have_quotes = 0;
@@ -185,7 +186,7 @@ public char * shell_quote(char *s)
/*
* Allocate and construct the new string.
*/
- newstr = p = (char *) ecalloc(len, sizeof(char));
+ newstr = np = (char *) ecalloc(len, sizeof(char));
if (use_quotes)
{
SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote);
@@ -198,12 +199,12 @@ public char * shell_quote(char *s)
/*
* Add the escape char.
*/
- strcpy(p, esc);
- p += esclen;
+ strcpy(np, esc);
+ np += esclen;
}
- *p++ = *s++;
+ *np++ = *s++;
}
- *p = '\0';
+ *np = '\0';
}
return (newstr);
}
--
2.43.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/a-znk/less.git
[email protected]:a-znk/less.git
a-znk
less
less
master

搜索帮助