1 Star 0 Fork 44

zhywyt/less

forked from src-openEuler/less 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-Implement-osc8_open.patch 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
wjiang 提交于 2024-04-22 14:29 . fix CVE-2024-32487
From 90d9d12ba9d3818a0074f33c5153b577d07aa8fd Mon Sep 17 00:00:00 2001
From: Mark Nudelman <markn@greenwoodsoftware.com>
Date: Tue, 16 Jan 2024 18:14:33 -0800
Subject: [PATCH] Implement osc8_open().
---
filename.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/filename.c b/filename.c
index 672dc94..5d7a5ef 100644
--- a/filename.c
+++ b/filename.c
@@ -136,7 +136,7 @@ static int metachar(char c)
/*
* Insert a backslash before each metacharacter in a string.
*/
-public char * shell_quote(constant char *s)
+public char * shell_quoten(constant char *s, size_t slen)
{
constant char *p;
char *np;
@@ -151,7 +151,7 @@ public char * shell_quote(constant char *s)
* Determine how big a string we need to allocate.
*/
len = 1; /* Trailing null byte */
- for (p = s; *p != '\0'; p++)
+ for (p = s; p < s + slen; p++)
{
len++;
if (*p == openquote || *p == closequote)
@@ -181,7 +181,7 @@ public char * shell_quote(constant char *s)
* We can't quote a string that contains quotes.
*/
return (NULL);
- len = (int) strlen(s) + 3;
+ len = slen + 3;
}
/*
* Allocate and construct the new string.
@@ -189,10 +189,11 @@ public char * shell_quote(constant char *s)
newstr = np = (char *) ecalloc(len, sizeof(char));
if (use_quotes)
{
- SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote);
+ SNPRINTF4(newstr, len, "%c%.*s%c", openquote, (int) slen, s, closequote);
} else
{
- while (*s != '\0')
+ constant char *es = s + slen;
+ while (s < es)
{
if (metachar(*s))
{
@@ -209,6 +210,11 @@ public char * shell_quote(constant char *s)
return (newstr);
}
+public char * shell_quote(char *s)
+{
+ return shell_quoten(s, strlen(s));
+}
+
/*
* Return a pathname that points to a specified file in a specified directory.
* Return NULL if the file does not exist in the directory.
--
2.43.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhy2216095277/less.git
git@gitee.com:zhy2216095277/less.git
zhy2216095277
less
less
master

搜索帮助