b130412
			     BASH PATCH REPORT
b130412
			     =================
b130412
b130412
Bash-Release: 3.2
b130412
Patch-ID: bash32-010
b130412
b130412
Bug-Reported-by:	Ryan Waldron <rew@erebor.com>
b130412
Bug-Reference-ID:	<20070119065603.546D011E9C@kansas.erebor.com>
b130412
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2007-01/msg00059.html
b130412
b130412
Bug-Description:
b130412
b130412
The glibc implementation of regcomp/regexec does not allow backslashes to
b130412
escape "ordinary" pattern characters when matching.  Bash used backslashes
b130412
to quote all characters when the pattern argument to the [[ special
b130412
command's =~ operator was quoted.  This caused the match to fail on Linux
b130412
and other systems using GNU libc.
b130412
b130412
Patch:
b130412
b130412
*** ../bash-3.2.9/pathexp.h	Sat Feb 19 17:23:18 2005
b130412
--- pathexp.h	Wed Jan 31 22:53:16 2007
b130412
***************
b130412
*** 1,5 ****
b130412
  /* pathexp.h -- The shell interface to the globbing library. */
b130412
  
b130412
! /* Copyright (C) 1987-2005 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
--- 1,5 ----
b130412
  /* pathexp.h -- The shell interface to the globbing library. */
b130412
  
b130412
! /* Copyright (C) 1987-2007 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
***************
b130412
*** 33,36 ****
b130412
--- 33,37 ----
b130412
  #define QGLOB_CVTNULL	0x01	/* convert QUOTED_NULL strings to '\0' */
b130412
  #define QGLOB_FILENAME	0x02	/* do correct quoting for matching filenames */
b130412
+ #define QGLOB_REGEXP	0x04	/* quote an ERE for regcomp/regexec */
b130412
  
b130412
  #if defined (EXTENDED_GLOB)
b130412
*** ../bash-3.2.9/pathexp.c	Mon May  6 13:43:05 2002
b130412
--- pathexp.c	Mon Feb 26 16:59:23 2007
b130412
***************
b130412
*** 1,5 ****
b130412
  /* pathexp.c -- The shell interface to the globbing library. */
b130412
  
b130412
! /* Copyright (C) 1995-2002 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
--- 1,5 ----
b130412
  /* pathexp.c -- The shell interface to the globbing library. */
b130412
  
b130412
! /* Copyright (C) 1995-2007 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
***************
b130412
*** 111,114 ****
b130412
--- 111,141 ----
b130412
  }
b130412
  
b130412
+ /* Return 1 if C is a character that is `special' in a POSIX ERE and needs to
b130412
+    be quoted to match itself. */
b130412
+ static inline int
b130412
+ ere_char (c)
b130412
+      int c;
b130412
+ {
b130412
+   switch (c)
b130412
+     {
b130412
+     case '.':
b130412
+     case '[':
b130412
+     case '\\':
b130412
+     case '(':
b130412
+     case ')':
b130412
+     case '*':
b130412
+     case '+':
b130412
+     case '?':
b130412
+     case '{':
b130412
+     case '|':
b130412
+     case '^':
b130412
+     case '$':
b130412
+       return 1;
b130412
+     default: 
b130412
+       return 0;
b130412
+     }
b130412
+   return (0);
b130412
+ }
b130412
+ 
b130412
  /* PATHNAME can contain characters prefixed by CTLESC; this indicates
b130412
     that the character is to be quoted.  We quote it here in the style
b130412
***************
b130412
*** 143,146 ****
b130412
--- 170,175 ----
b130412
  	  if ((qflags & QGLOB_FILENAME) && pathname[i+1] == '/')
b130412
  	    continue;
b130412
+ 	  if ((qflags & QGLOB_REGEXP) && ere_char (pathname[i+1]) == 0)
b130412
+ 	    continue;
b130412
  	  temp[j++] = '\\';
b130412
  	  i++;
b130412
*** ../bash-3.2.9/subst.c	Tue Nov  7 16:14:41 2006
b130412
--- subst.c	Wed Jan 31 23:09:58 2007
b130412
***************
b130412
*** 5,9 ****
b130412
       beauty, but, hey, you're alright.'' */
b130412
  
b130412
! /* Copyright (C) 1987-2006 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
--- 5,9 ----
b130412
       beauty, but, hey, you're alright.'' */
b130412
  
b130412
! /* Copyright (C) 1987-2007 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
***************
b130412
*** 2647,2655 ****
b130412
  /* This needs better error handling. */
b130412
  /* Expand W for use as an argument to a unary or binary operator in a
b130412
!    [[...]] expression.  If SPECIAL is nonzero, this is the rhs argument
b130412
     to the != or == operator, and should be treated as a pattern.  In
b130412
!    this case, we quote the string specially for the globbing code.  The
b130412
!    caller is responsible for removing the backslashes if the unquoted
b130412
!    words is needed later. */   
b130412
  char *
b130412
  cond_expand_word (w, special)
b130412
--- 2647,2656 ----
b130412
  /* This needs better error handling. */
b130412
  /* Expand W for use as an argument to a unary or binary operator in a
b130412
!    [[...]] expression.  If SPECIAL is 1, this is the rhs argument
b130412
     to the != or == operator, and should be treated as a pattern.  In
b130412
!    this case, we quote the string specially for the globbing code.  If
b130412
!    SPECIAL is 2, this is an rhs argument for the =~ operator, and should
b130412
!    be quoted appropriately for regcomp/regexec.  The caller is responsible
b130412
!    for removing the backslashes if the unquoted word is needed later. */   
b130412
  char *
b130412
  cond_expand_word (w, special)
b130412
***************
b130412
*** 2659,2662 ****
b130412
--- 2660,2664 ----
b130412
    char *r, *p;
b130412
    WORD_LIST *l;
b130412
+   int qflags;
b130412
  
b130412
    if (w->word == 0 || w->word[0] == '\0')
b130412
***************
b130412
*** 2673,2678 ****
b130412
        else
b130412
  	{
b130412
  	  p = string_list (l);
b130412
! 	  r = quote_string_for_globbing (p, QGLOB_CVTNULL);
b130412
  	  free (p);
b130412
  	}
b130412
--- 2675,2683 ----
b130412
        else
b130412
  	{
b130412
+ 	  qflags = QGLOB_CVTNULL;
b130412
+ 	  if (special == 2)
b130412
+ 	    qflags |= QGLOB_REGEXP;
b130412
  	  p = string_list (l);
b130412
! 	  r = quote_string_for_globbing (p, qflags);
b130412
  	  free (p);
b130412
  	}
b130412
*** ../bash-3.2.9/execute_cmd.c	Sat Aug 26 00:23:17 2006
b130412
--- execute_cmd.c	Wed Jan 31 23:12:06 2007
b130412
***************
b130412
*** 1,5 ****
b130412
  /* execute_cmd.c -- Execute a COMMAND structure. */
b130412
  
b130412
! /* Copyright (C) 1987-2005 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
--- 1,5 ----
b130412
  /* execute_cmd.c -- Execute a COMMAND structure. */
b130412
  
b130412
! /* Copyright (C) 1987-2007 Free Software Foundation, Inc.
b130412
  
b130412
     This file is part of GNU Bash, the Bourne Again SHell.
b130412
***************
b130412
*** 2547,2551 ****
b130412
        if (arg1 == 0)
b130412
  	arg1 = nullstr;
b130412
!       arg2 = cond_expand_word (cond->right->op, patmatch||rmatch);
b130412
        if (arg2 == 0)
b130412
  	arg2 = nullstr;
b130412
--- 2547,2551 ----
b130412
        if (arg1 == 0)
b130412
  	arg1 = nullstr;
b130412
!       arg2 = cond_expand_word (cond->right->op, rmatch ? 2 : (patmatch ? 1 : 0));
b130412
        if (arg2 == 0)
b130412
  	arg2 = nullstr;
b130412
*** ../bash-3.2/patchlevel.h	Thu Apr 13 08:31:04 2006
b130412
--- patchlevel.h	Mon Oct 16 14:22:54 2006
b130412
***************
b130412
*** 26,30 ****
b130412
     looks for to find the patch level (for the sccs version string). */
b130412
  
b130412
! #define PATCHLEVEL 9
b130412
  
b130412
  #endif /* _PATCHLEVEL_H_ */
b130412
--- 26,30 ----
b130412
     looks for to find the patch level (for the sccs version string). */
b130412
  
b130412
! #define PATCHLEVEL 10
b130412
  
b130412
  #endif /* _PATCHLEVEL_H_ */