Tim Waugh 393b61
			     BASH PATCH REPORT
Tim Waugh 393b61
			     =================
Tim Waugh 393b61
Tim Waugh 393b61
Bash-Release: 3.2
Tim Waugh 393b61
Patch-ID: bash32-003
Tim Waugh 393b61
Tim Waugh 393b61
Bug-Reported-by:	John Gatewood Ham <zappaman@buraphalinux.org>
Tim Waugh 393b61
Bug-Reference-ID:	<Pine.LNX.4.64.0610121334140.15558@www.buraphalinux.org>
Tim Waugh 393b61
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2006-10/msg00045.html
Tim Waugh 393b61
Tim Waugh 393b61
Bug-Description:
Tim Waugh 393b61
Tim Waugh 393b61
When using the conditional command's `=~' operator to match regular
Tim Waugh 393b61
expressions, the parser did not skip over shell metacharacters in the
Tim Waugh 393b61
regular expression, leading to syntax errors.
Tim Waugh 393b61
Tim Waugh 393b61
Patch:
Tim Waugh 393b61
Tim Waugh 393b61
*** ../bash-3.2-patched/parse.y	Tue Oct 17 11:45:20 2006
Tim Waugh 393b61
--- parse.y	Sat Oct 14 14:56:16 2006
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 1029,1034 ****
Tim Waugh 393b61
--- 1029,1035 ----
Tim Waugh 393b61
  #define PST_CMDTOKEN	0x1000		/* command token OK - unused */
Tim Waugh 393b61
  #define PST_COMPASSIGN	0x2000		/* parsing x=(...) compound assignment */
Tim Waugh 393b61
  #define PST_ASSIGNOK	0x4000		/* assignment statement ok in this context */
Tim Waugh 393b61
+ #define PST_REGEXP	0x8000		/* parsing an ERE/BRE as a single word */
Tim Waugh 393b61
  
Tim Waugh 393b61
  /* Initial size to allocate for tokens, and the
Tim Waugh 393b61
     amount to grow them by. */
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 2591,2596 ****
Tim Waugh 393b61
--- 2592,2600 ----
Tim Waugh 393b61
        return (character);
Tim Waugh 393b61
      }
Tim Waugh 393b61
  
Tim Waugh 393b61
+   if (parser_state & PST_REGEXP)
Tim Waugh 393b61
+     goto tokword;
Tim Waugh 393b61
+ 
Tim Waugh 393b61
    /* Shell meta-characters. */
Tim Waugh 393b61
    if MBTEST(shellmeta (character) && ((parser_state & PST_DBLPAREN) == 0))
Tim Waugh 393b61
      {
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 2698,2703 ****
Tim Waugh 393b61
--- 2702,2708 ----
Tim Waugh 393b61
    if MBTEST(character == '-' && (last_read_token == LESS_AND || last_read_token == GREATER_AND))
Tim Waugh 393b61
      return (character);
Tim Waugh 393b61
  
Tim Waugh 393b61
+ tokword:
Tim Waugh 393b61
    /* Okay, if we got this far, we have to read a word.  Read one,
Tim Waugh 393b61
       and then check it against the known ones. */
Tim Waugh 393b61
    result = read_token_word (character);
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 3202,3209 ****
Tim Waugh 393b61
        if (tok == WORD && test_binop (yylval.word->word))
Tim Waugh 393b61
  	op = yylval.word;
Tim Waugh 393b61
  #if defined (COND_REGEXP)
Tim Waugh 393b61
!       else if (tok == WORD && STREQ (yylval.word->word,"=~"))
Tim Waugh 393b61
! 	op = yylval.word;
Tim Waugh 393b61
  #endif
Tim Waugh 393b61
        else if (tok == '<' || tok == '>')
Tim Waugh 393b61
  	op = make_word_from_token (tok);  /* ( */
Tim Waugh 393b61
--- 3207,3217 ----
Tim Waugh 393b61
        if (tok == WORD && test_binop (yylval.word->word))
Tim Waugh 393b61
  	op = yylval.word;
Tim Waugh 393b61
  #if defined (COND_REGEXP)
Tim Waugh 393b61
!       else if (tok == WORD && STREQ (yylval.word->word, "=~"))
Tim Waugh 393b61
! 	{
Tim Waugh 393b61
! 	  op = yylval.word;
Tim Waugh 393b61
! 	  parser_state |= PST_REGEXP;
Tim Waugh 393b61
! 	}
Tim Waugh 393b61
  #endif
Tim Waugh 393b61
        else if (tok == '<' || tok == '>')
Tim Waugh 393b61
  	op = make_word_from_token (tok);  /* ( */
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 3234,3239 ****
Tim Waugh 393b61
--- 3242,3248 ----
Tim Waugh 393b61
  
Tim Waugh 393b61
        /* rhs */
Tim Waugh 393b61
        tok = read_token (READ);
Tim Waugh 393b61
+       parser_state &= ~PST_REGEXP;
Tim Waugh 393b61
        if (tok == WORD)
Tim Waugh 393b61
  	{
Tim Waugh 393b61
  	  tright = make_cond_node (COND_TERM, yylval.word, (COND_COM *)NULL, (COND_COM *)NULL);
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 3419,3427 ****
Tim Waugh 393b61
  	  goto next_character;
Tim Waugh 393b61
  	}
Tim Waugh 393b61
  
Tim Waugh 393b61
  #ifdef EXTENDED_GLOB
Tim Waugh 393b61
        /* Parse a ksh-style extended pattern matching specification. */
Tim Waugh 393b61
!       if (extended_glob && PATTERN_CHAR (character))
Tim Waugh 393b61
  	{
Tim Waugh 393b61
  	  peek_char = shell_getc (1);
Tim Waugh 393b61
  	  if MBTEST(peek_char == '(')		/* ) */
Tim Waugh 393b61
--- 3428,3461 ----
Tim Waugh 393b61
  	  goto next_character;
Tim Waugh 393b61
  	}
Tim Waugh 393b61
  
Tim Waugh 393b61
+ #ifdef COND_REGEXP
Tim Waugh 393b61
+       /* When parsing a regexp as a single word inside a conditional command,
Tim Waugh 393b61
+ 	 we need to special-case characters special to both the shell and
Tim Waugh 393b61
+ 	 regular expressions.  Right now, that is only '(' and '|'. */ /*)*/
Tim Waugh 393b61
+       if MBTEST((parser_state & PST_REGEXP) && (character == '(' || character == '|'))		/*)*/
Tim Waugh 393b61
+         {
Tim Waugh 393b61
+           if (character == '|')
Tim Waugh 393b61
+             goto got_character;
Tim Waugh 393b61
+ 
Tim Waugh 393b61
+ 	  push_delimiter (dstack, character);
Tim Waugh 393b61
+ 	  ttok = parse_matched_pair (cd, '(', ')', &ttoklen, 0);
Tim Waugh 393b61
+ 	  pop_delimiter (dstack);
Tim Waugh 393b61
+ 	  if (ttok == &matched_pair_error)
Tim Waugh 393b61
+ 	    return -1;		/* Bail immediately. */
Tim Waugh 393b61
+ 	  RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
Tim Waugh 393b61
+ 				  token_buffer_size, TOKEN_DEFAULT_GROW_SIZE);
Tim Waugh 393b61
+ 	  token[token_index++] = character;
Tim Waugh 393b61
+ 	  strcpy (token + token_index, ttok);
Tim Waugh 393b61
+ 	  token_index += ttoklen;
Tim Waugh 393b61
+ 	  FREE (ttok);
Tim Waugh 393b61
+ 	  dollar_present = all_digit_token = 0;
Tim Waugh 393b61
+ 	  goto next_character;
Tim Waugh 393b61
+         }
Tim Waugh 393b61
+ #endif /* COND_REGEXP */
Tim Waugh 393b61
+ 
Tim Waugh 393b61
  #ifdef EXTENDED_GLOB
Tim Waugh 393b61
        /* Parse a ksh-style extended pattern matching specification. */
Tim Waugh 393b61
!       if MBTEST(extended_glob && PATTERN_CHAR (character))
Tim Waugh 393b61
  	{
Tim Waugh 393b61
  	  peek_char = shell_getc (1);
Tim Waugh 393b61
  	  if MBTEST(peek_char == '(')		/* ) */
Tim Waugh 393b61
Tim Waugh 393b61
*** ../bash-3.2/patchlevel.h	Thu Apr 13 08:31:04 2006
Tim Waugh 393b61
--- patchlevel.h	Mon Oct 16 14:22:54 2006
Tim Waugh 393b61
***************
Tim Waugh 393b61
*** 26,30 ****
Tim Waugh 393b61
     looks for to find the patch level (for the sccs version string). */
Tim Waugh 393b61
  
Tim Waugh 393b61
! #define PATCHLEVEL 2
Tim Waugh 393b61
  
Tim Waugh 393b61
  #endif /* _PATCHLEVEL_H_ */
Tim Waugh 393b61
--- 26,30 ----
Tim Waugh 393b61
     looks for to find the patch level (for the sccs version string). */
Tim Waugh 393b61
  
Tim Waugh 393b61
! #define PATCHLEVEL 3
Tim Waugh 393b61
  
Tim Waugh 393b61
  #endif /* _PATCHLEVEL_H_ */
Tim Waugh 393b61