shells/bash: fix nested brace expansion, from upstream

This fixes a reported problem in sysutils/neofetch.
This commit is contained in:
naddy 2022-11-04 20:20:29 +00:00
parent facd39dc37
commit 8e0d851ebe
2 changed files with 43 additions and 0 deletions

View File

@ -2,6 +2,7 @@ COMMENT= GNU Bourne Again Shell
DISTNAME= bash-5.2
PKGNAME= bash-5.2.2
REVISION= 0
CATEGORIES= shells
HOMEPAGE= https://www.gnu.org/software/bash/

View File

@ -0,0 +1,42 @@
Fix nested brace expansion.
https://lists.gnu.org/archive/html/bug-bash/2022-10/txtAAVHexDehk.txt
Index: subst.c
--- subst.c.orig
+++ subst.c
@@ -1798,6 +1798,9 @@ extract_heredoc_dolbrace_string (string, sindex, quote
return (result);
}
+#define PARAMEXPNEST_MAX 32 // for now
+static int dbstate[PARAMEXPNEST_MAX];
+
/* Extract a parameter expansion expression within ${ and } from STRING.
Obey the Posix.2 rules for finding the ending `}': count braces while
skipping over enclosed quoted strings and command substitutions.
@@ -1828,6 +1831,8 @@ extract_dollar_brace_string (string, sindex, quoted, f
if (quoted == Q_HERE_DOCUMENT && dolbrace_state == DOLBRACE_QUOTE && (flags & SX_NOALLOC) == 0)
return (extract_heredoc_dolbrace_string (string, sindex, quoted, flags));
+ dbstate[0] = dolbrace_state;
+
pass_character = 0;
nesting_level = 1;
slen = strlen (string + *sindex) + *sindex;
@@ -1852,6 +1857,8 @@ extract_dollar_brace_string (string, sindex, quoted, f
if (string[i] == '$' && string[i+1] == LBRACE)
{
+ if (nesting_level < PARAMEXPNEST_MAX)
+ dbstate[nesting_level] = dolbrace_state;
nesting_level++;
i += 2;
if (dolbrace_state == DOLBRACE_QUOTE || dolbrace_state == DOLBRACE_WORD)
@@ -1864,6 +1871,7 @@ extract_dollar_brace_string (string, sindex, quoted, f
nesting_level--;
if (nesting_level == 0)
break;
+ dolbrace_state = (nesting_level < PARAMEXPNEST_MAX) ? dbstate[nesting_level] : dbstate[0]; /* Guess using initial state */
i++;
continue;
}