less/backport-Implement-osc8_open.patch
wangjiang 5cc1abcb8a fix CVE-2024-32487
(cherry picked from commit af9f9c64c33c5dcc7eb71d2046b649321fbac25f)
2024-04-22 16:43:52 +08:00

72 lines
1.7 KiB
Diff

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 | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/filename.c b/filename.c
index 482d264..64d9ded 100644
--- a/filename.c
+++ b/filename.c
@@ -139,8 +139,9 @@ metachar(c)
* Insert a backslash before each metacharacter in a string.
*/
public char *
-shell_quote(s)
+shell_quoten(s, slen)
char *s;
+ size_t slen;
{
constant char *p;
char *np;
@@ -155,7 +156,7 @@ shell_quote(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)
@@ -185,7 +186,7 @@ shell_quote(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.
@@ -193,10 +194,11 @@ shell_quote(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))
{
@@ -213,6 +215,11 @@ shell_quote(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