churchyard / rpms / bash

Forked from rpms/bash 5 years ago
Clone
Roman Rakus 6c00439
			     BASH PATCH REPORT
Roman Rakus 6c00439
			     =================
Roman Rakus 6c00439
Roman Rakus 6c00439
Bash-Release:	4.2
Roman Rakus 6c00439
Patch-ID:	bash42-030
Roman Rakus 6c00439
Roman Rakus 6c00439
Bug-Reported-by:	Roman Rakus <rrakus@redhat.com>
Roman Rakus 6c00439
Bug-Reference-ID:	<4D7DD91E.7040808@redhat.com>
Roman Rakus 6c00439
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2011-03/msg00126.html
Roman Rakus 6c00439
Roman Rakus 6c00439
Bug-Description:
Roman Rakus 6c00439
Roman Rakus 6c00439
When attempting to glob strings in a multibyte locale, and those strings
Roman Rakus 6c00439
contain invalid multibyte characters that cause mbsnrtowcs to return 0,
Roman Rakus 6c00439
the globbing code loops infinitely.
Roman Rakus 6c00439
Roman Rakus 6c00439
Patch (apply with `patch -p0'):
Roman Rakus 6c00439
Roman Rakus 6c00439
*** ../bash-4.2-patched/lib/glob/xmbsrtowcs.c	2010-05-30 18:36:27.000000000 -0400
Roman Rakus 6c00439
--- lib/glob/xmbsrtowcs.c	2011-03-22 16:06:47.000000000 -0400
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 36,39 ****
Roman Rakus 6c00439
--- 36,41 ----
Roman Rakus 6c00439
  #if HANDLE_MULTIBYTE
Roman Rakus 6c00439
  
Roman Rakus 6c00439
+ #define WSBUF_INC 32
Roman Rakus 6c00439
+ 
Roman Rakus 6c00439
  #ifndef FREE
Roman Rakus 6c00439
  #  define FREE(x)	do { if (x) free (x); } while (0)
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 149,153 ****
Roman Rakus 6c00439
    size_t wcnum;		/* Number of wide characters in WSBUF */
Roman Rakus 6c00439
    mbstate_t state;	/* Conversion State */
Roman Rakus 6c00439
!   size_t wcslength;	/* Number of wide characters produced by the conversion. */
Roman Rakus 6c00439
    const char *end_or_backslash;
Roman Rakus 6c00439
    size_t nms;	/* Number of multibyte characters to convert at one time. */
Roman Rakus 6c00439
--- 151,155 ----
Roman Rakus 6c00439
    size_t wcnum;		/* Number of wide characters in WSBUF */
Roman Rakus 6c00439
    mbstate_t state;	/* Conversion State */
Roman Rakus 6c00439
!   size_t n, wcslength;	/* Number of wide characters produced by the conversion. */
Roman Rakus 6c00439
    const char *end_or_backslash;
Roman Rakus 6c00439
    size_t nms;	/* Number of multibyte characters to convert at one time. */
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 172,176 ****
Roman Rakus 6c00439
        tmp_p = p;
Roman Rakus 6c00439
        tmp_state = state;
Roman Rakus 6c00439
!       wcslength = mbsnrtowcs(NULL, &tmp_p, nms, 0, &tmp_state);
Roman Rakus 6c00439
  
Roman Rakus 6c00439
        /* Conversion failed. */
Roman Rakus 6c00439
--- 174,189 ----
Roman Rakus 6c00439
        tmp_p = p;
Roman Rakus 6c00439
        tmp_state = state;
Roman Rakus 6c00439
! 
Roman Rakus 6c00439
!       if (nms == 0 && *p == '\\')	/* special initial case */
Roman Rakus 6c00439
! 	nms = wcslength = 1;
Roman Rakus 6c00439
!       else
Roman Rakus 6c00439
! 	wcslength = mbsnrtowcs (NULL, &tmp_p, nms, 0, &tmp_state);
Roman Rakus 6c00439
! 
Roman Rakus 6c00439
!       if (wcslength == 0)
Roman Rakus 6c00439
! 	{
Roman Rakus 6c00439
! 	  tmp_p = p;		/* will need below */
Roman Rakus 6c00439
! 	  tmp_state = state;
Roman Rakus 6c00439
! 	  wcslength = 1;	/* take a single byte */
Roman Rakus 6c00439
! 	}
Roman Rakus 6c00439
  
Roman Rakus 6c00439
        /* Conversion failed. */
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 187,191 ****
Roman Rakus 6c00439
  	  wchar_t *wstmp;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
! 	  wsbuf_size = wcnum+wcslength+1;	/* 1 for the L'\0' or the potential L'\\' */
Roman Rakus 6c00439
  
Roman Rakus 6c00439
  	  wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
Roman Rakus 6c00439
--- 200,205 ----
Roman Rakus 6c00439
  	  wchar_t *wstmp;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
! 	  while (wsbuf_size < wcnum+wcslength+1) /* 1 for the L'\0' or the potential L'\\' */
Roman Rakus 6c00439
! 	    wsbuf_size += WSBUF_INC;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
  	  wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 200,207 ****
Roman Rakus 6c00439
  
Roman Rakus 6c00439
        /* Perform the conversion. This is assumed to return 'wcslength'.
Roman Rakus 6c00439
!        * It may set 'p' to NULL. */
Roman Rakus 6c00439
!       mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
Roman Rakus 6c00439
  
Roman Rakus 6c00439
!       wcnum += wcslength;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
        if (mbsinit (&state) && (p != NULL) && (*p == '\\'))
Roman Rakus 6c00439
--- 214,229 ----
Roman Rakus 6c00439
  
Roman Rakus 6c00439
        /* Perform the conversion. This is assumed to return 'wcslength'.
Roman Rakus 6c00439
! 	 It may set 'p' to NULL. */
Roman Rakus 6c00439
!       n = mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
Roman Rakus 6c00439
  
Roman Rakus 6c00439
!       /* Compensate for taking single byte on wcs conversion failure above. */
Roman Rakus 6c00439
!       if (wcslength == 1 && (n == 0 || n == (size_t)-1))
Roman Rakus 6c00439
! 	{
Roman Rakus 6c00439
! 	  state = tmp_state;
Roman Rakus 6c00439
! 	  p = tmp_p;
Roman Rakus 6c00439
! 	  wsbuf[wcnum++] = *p++;
Roman Rakus 6c00439
! 	}
Roman Rakus 6c00439
!       else
Roman Rakus 6c00439
!         wcnum += wcslength;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
        if (mbsinit (&state) && (p != NULL) && (*p == '\\'))
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 231,236 ****
Roman Rakus 6c00439
     of DESTP and INDICESP are NULL. */
Roman Rakus 6c00439
  
Roman Rakus 6c00439
- #define WSBUF_INC 32
Roman Rakus 6c00439
- 
Roman Rakus 6c00439
  size_t
Roman Rakus 6c00439
  xdupmbstowcs (destp, indicesp, src)
Roman Rakus 6c00439
--- 253,256 ----
Roman Rakus 6c00439
*** ../bash-4.2-patched/lib/glob/glob.c	2009-11-14 18:39:30.000000000 -0500
Roman Rakus 6c00439
--- lib/glob/glob.c	2012-07-07 12:09:56.000000000 -0400
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 201,206 ****
Roman Rakus 6c00439
    size_t pat_n, dn_n;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
    pat_n = xdupmbstowcs (&pat_wc, NULL, pat);
Roman Rakus 6c00439
!   dn_n = xdupmbstowcs (&dn_wc, NULL, dname);
Roman Rakus 6c00439
  
Roman Rakus 6c00439
    ret = 0;
Roman Rakus 6c00439
--- 201,209 ----
Roman Rakus 6c00439
    size_t pat_n, dn_n;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
+   pat_wc = dn_wc = (wchar_t *)NULL;
Roman Rakus 6c00439
+ 
Roman Rakus 6c00439
    pat_n = xdupmbstowcs (&pat_wc, NULL, pat);
Roman Rakus 6c00439
!   if (pat_n != (size_t)-1)
Roman Rakus 6c00439
!     dn_n = xdupmbstowcs (&dn_wc, NULL, dname);
Roman Rakus 6c00439
  
Roman Rakus 6c00439
    ret = 0;
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 222,225 ****
Roman Rakus 6c00439
--- 225,230 ----
Roman Rakus 6c00439
  	ret = 1;
Roman Rakus 6c00439
      }
Roman Rakus 6c00439
+   else
Roman Rakus 6c00439
+     ret = skipname (pat, dname, flags);
Roman Rakus 6c00439
  
Roman Rakus 6c00439
    FREE (pat_wc);
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 267,272 ****
Roman Rakus 6c00439
    n = xdupmbstowcs (&wpathname, NULL, pathname);
Roman Rakus 6c00439
    if (n == (size_t) -1)
Roman Rakus 6c00439
!     /* Something wrong. */
Roman Rakus 6c00439
!     return;
Roman Rakus 6c00439
    orig_wpathname = wpathname;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
--- 272,280 ----
Roman Rakus 6c00439
    n = xdupmbstowcs (&wpathname, NULL, pathname);
Roman Rakus 6c00439
    if (n == (size_t) -1)
Roman Rakus 6c00439
!     {
Roman Rakus 6c00439
!       /* Something wrong.  Fall back to single-byte */
Roman Rakus 6c00439
!       udequote_pathname (pathname);
Roman Rakus 6c00439
!       return;
Roman Rakus 6c00439
!     }
Roman Rakus 6c00439
    orig_wpathname = wpathname;
Roman Rakus 6c00439
  
Roman Rakus 6c00439
*** ../bash-4.2-patched/patchlevel.h	Sat Jun 12 20:14:48 2010
Roman Rakus 6c00439
--- patchlevel.h	Thu Feb 24 21:41:34 2011
Roman Rakus 6c00439
***************
Roman Rakus 6c00439
*** 26,30 ****
Roman Rakus 6c00439
     looks for to find the patch level (for the sccs version string). */
Roman Rakus 6c00439
  
Roman Rakus 6c00439
! #define PATCHLEVEL 29
Roman Rakus 6c00439
  
Roman Rakus 6c00439
  #endif /* _PATCHLEVEL_H_ */
Roman Rakus 6c00439
--- 26,30 ----
Roman Rakus 6c00439
     looks for to find the patch level (for the sccs version string). */
Roman Rakus 6c00439
  
Roman Rakus 6c00439
! #define PATCHLEVEL 30
Roman Rakus 6c00439
  
Roman Rakus 6c00439
  #endif /* _PATCHLEVEL_H_ */