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