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