]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.2 patch 4: fix for nested brace expansions and brackets
authorChet Ramey <chet.ramey@case.edu>
Mon, 7 Nov 2022 16:40:28 +0000 (11:40 -0500)
committerChet Ramey <chet.ramey@case.edu>
Mon, 7 Nov 2022 16:40:28 +0000 (11:40 -0500)
patchlevel.h
subst.c

index 40f26f7b395cc0c89e4bf0c7d05006b771bb333b..16233d5a59cc51cfec37aa0204005cad3c71fb49 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 3
+#define PATCHLEVEL 4
 
 #endif /* _PATCHLEVEL_H_ */
diff --git a/subst.c b/subst.c
index 93b91606c6b1891f012d3ebef6a59d6d728083d1..295d3aad52e0f177b37661457ae6fb84e8c67897 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -1798,6 +1798,9 @@ extract_heredoc_dolbrace_string (string, sindex, quoted, flags)
   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, flags)
   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, flags)
 
       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, flags)
          nesting_level--;
          if (nesting_level == 0)
            break;
+         dolbrace_state = (nesting_level < PARAMEXPNEST_MAX) ? dbstate[nesting_level] : dbstate[0];    /* Guess using initial state */
          i++;
          continue;
        }