On 10/20/22 5:03 AM, Martin von Gagern wrote:

Bash Version: 5.2
Patch Level: !PATCHLEVEL!
Release Status: release

Description:

Some substitutions that used to work pre 5.2 are failing starting in
5.2. I did a git bisect on that, it's the initial 5.2 commit which
broke this, 
https://git.savannah.gnu.org/cgit/bash.git/commit/?h=bash-5.2&id=74091dd4e8086db518b30df7f222691524469998.

According to my reproducing example below, this appears to be due to a
combination of conditional substitution, a variable enclosed in curly
braces and an unbalanced opening square bracket that I think should
only be considered as text without any semantic relevance in this
position.

Thanks for the report. This came up a couple weeks ago in

https://lists.gnu.org/archive/html/bug-bash/2022-10/msg00022.html

and is fixed in the devel branch. I've attached the patch that fixes it.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/
*** ../bash-5.2-patched/subst.c 2022-10-05 10:22:02.000000000 -0400
--- subst.c     2022-10-06 15:19:08.000000000 -0400
***************
*** 1799,1802 ****
--- 1804,1810 ----
  }
  
+ #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
***************
*** 1829,1832 ****
--- 1837,1842 ----
      return (extract_heredoc_dolbrace_string (string, sindex, quoted, flags));
  
+   dbstate[0] = dolbrace_state;
+ 
    pass_character = 0;
    nesting_level = 1;
***************
*** 1853,1856 ****
--- 1863,1868 ----
        if (string[i] == '$' && string[i+1] == LBRACE)
        {
+         if (nesting_level < PARAMEXPNEST_MAX)
+           dbstate[nesting_level] = dolbrace_state;
          nesting_level++;
          i += 2;
***************
*** 1865,1868 ****
--- 1877,1881 ----
          if (nesting_level == 0)
            break;
+         dolbrace_state = (nesting_level < PARAMEXPNEST_MAX) ? 
dbstate[nesting_level] : dbstate[0];    /* Guess using initial state */
          i++;
          continue;

Reply via email to