patches/glibc/2.9/410-2.9-fnmatch.patch
branchnewlib
changeset 1365 c4d124ed9f8e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/glibc/2.9/410-2.9-fnmatch.patch	Sun Apr 19 16:17:11 2009 +0000
     1.3 @@ -0,0 +1,64 @@
     1.4 +Original patch from: gentoo/src/patchsets/glibc/2.9/5021_all_2.9-fnmatch.patch
     1.5 +
     1.6 +-= BEGIN original header =-
     1.7 +http://sourceware.org/ml/libc-hacker/2002-11/msg00071.html
     1.8 +
     1.9 +When fnmatch detects an invalid multibyte character it should fall back to
    1.10 +single byte matching, so that "*" has a chance to match such a string.
    1.11 +
    1.12 +Andreas.
    1.13 +
    1.14 +2005-04-12  Andreas Schwab  <schwab@suse.de>
    1.15 +
    1.16 +	* posix/fnmatch.c (fnmatch): If conversion to wide character
    1.17 +	fails fall back to single byte matching.
    1.18 +
    1.19 +-= END original header =-
    1.20 +
    1.21 +diff -durN glibc-2_9.orig/posix/fnmatch.c glibc-2_9/posix/fnmatch.c
    1.22 +--- glibc-2_9.orig/posix/fnmatch.c	2007-07-28 22:35:00.000000000 +0200
    1.23 ++++ glibc-2_9/posix/fnmatch.c	2009-02-02 22:01:25.000000000 +0100
    1.24 +@@ -327,6 +327,7 @@
    1.25 + # if HANDLE_MULTIBYTE
    1.26 +   if (__builtin_expect (MB_CUR_MAX, 1) != 1)
    1.27 +     {
    1.28 ++      const char *orig_pattern = pattern;
    1.29 +       mbstate_t ps;
    1.30 +       size_t n;
    1.31 +       const char *p;
    1.32 +@@ -382,10 +383,8 @@
    1.33 + 	  wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
    1.34 + 	  n = mbsrtowcs (wstring, &p, n + 1, &ps);
    1.35 + 	  if (__builtin_expect (n == (size_t) -1, 0))
    1.36 +-	    /* Something wrong.
    1.37 +-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
    1.38 +-	       already done?  */
    1.39 +-	    return -1;
    1.40 ++	    /* Something wrong.  Fall back to single byte matching.  */
    1.41 ++	    goto try_singlebyte;
    1.42 + 	  if (p)
    1.43 + 	    {
    1.44 + 	      memset (&ps, '\0', sizeof (ps));
    1.45 +@@ -397,10 +396,8 @@
    1.46 + 	prepare_wstring:
    1.47 + 	  n = mbsrtowcs (NULL, &string, 0, &ps);
    1.48 + 	  if (__builtin_expect (n == (size_t) -1, 0))
    1.49 +-	    /* Something wrong.
    1.50 +-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
    1.51 +-	       already done?  */
    1.52 +-	    return -1;
    1.53 ++	    /* Something wrong.  Fall back to single byte matching.  */
    1.54 ++	    goto try_singlebyte;
    1.55 + 	  wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
    1.56 + 	  assert (mbsinit (&ps));
    1.57 + 	  (void) mbsrtowcs (wstring, &string, n + 1, &ps);
    1.58 +@@ -408,6 +405,9 @@
    1.59 + 
    1.60 +       return internal_fnwmatch (wpattern, wstring, wstring + n,
    1.61 + 				flags & FNM_PERIOD, flags, NULL);
    1.62 ++
    1.63 ++    try_singlebyte:
    1.64 ++      pattern = orig_pattern;
    1.65 +     }
    1.66 + # endif  /* mbstate_t and mbsrtowcs or _LIBC.  */
    1.67 +