ce426f
diff -Nru glibc-2.17-c758a686/posix/fnmatch.c glibc-2.17-c758a686/posix/fnmatch.c
ce426f
--- glibc-2.17-c758a686/posix/fnmatch.c	2012-01-01 07:16:32.000000000 -0500
ce426f
+++ glibc-2.17-c758a686/posix/fnmatch.c	2012-05-23 14:14:29.099461189 -0400
ce426f
@@ -333,6 +333,7 @@ fnmatch (pattern, string, flags)
ce426f
 # if HANDLE_MULTIBYTE
ce426f
   if (__builtin_expect (MB_CUR_MAX, 1) != 1)
ce426f
     {
ce426f
+      const char *orig_pattern = pattern;
ce426f
       mbstate_t ps;
ce426f
       size_t n;
ce426f
       const char *p;
ce426f
@@ -356,10 +357,8 @@ fnmatch (pattern, string, flags)
ce426f
 						 alloca_used);
ce426f
 	  n = mbsrtowcs (wpattern, &p, n + 1, &ps);
ce426f
 	  if (__builtin_expect (n == (size_t) -1, 0))
ce426f
-	    /* Something wrong.
ce426f
-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
ce426f
-	       already done?  */
ce426f
-	    return -1;
ce426f
+	    /* Something wrong: Fall back to single byte matching. */
ce426f
+	    goto try_singlebyte;
ce426f
 	  if (p)
ce426f
 	    {
ce426f
 	      memset (&ps, '\0', sizeof (ps));
ce426f
@@ -371,10 +370,8 @@ fnmatch (pattern, string, flags)
ce426f
 	prepare_wpattern:
ce426f
 	  n = mbsrtowcs (NULL, &pattern, 0, &ps);
ce426f
 	  if (__builtin_expect (n == (size_t) -1, 0))
ce426f
-	    /* Something wrong.
ce426f
-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
ce426f
-	       already done?  */
ce426f
-	    return -1;
ce426f
+	    /*Something wrong: Fall back to single byte matching. */
ce426f
+	    goto try_singlebyte;
ce426f
 	  if (__builtin_expect (n >= (size_t) -1 / sizeof (wchar_t), 0))
ce426f
 	    {
ce426f
 	      __set_errno (ENOMEM);
ce426f
@@ -401,14 +398,8 @@ fnmatch (pattern, string, flags)
ce426f
 						alloca_used);
ce426f
 	  n = mbsrtowcs (wstring, &p, n + 1, &ps);
ce426f
 	  if (__builtin_expect (n == (size_t) -1, 0))
ce426f
-	    {
ce426f
-	      /* Something wrong.
ce426f
-		 XXX Do we have to set `errno' to something which
ce426f
-		 mbsrtows hasn't already done?  */
ce426f
-	    free_return:
ce426f
-	      free (wpattern_malloc);
ce426f
-	      return -1;
ce426f
-	    }
ce426f
+	    /* Something wrong: Fall back to single byte matching. */
ce426f
+	    goto free_and_try_singlebyte;
ce426f
 	  if (p)
ce426f
 	    {
ce426f
 	      memset (&ps, '\0', sizeof (ps));
ce426f
@@ -420,10 +411,8 @@ fnmatch (pattern, string, flags)
ce426f
 	prepare_wstring:
ce426f
 	  n = mbsrtowcs (NULL, &string, 0, &ps);
ce426f
 	  if (__builtin_expect (n == (size_t) -1, 0))
ce426f
-	    /* Something wrong.
ce426f
-	       XXX Do we have to set `errno' to something which mbsrtows hasn't
ce426f
-	       already done?  */
ce426f
-	    goto free_return;
ce426f
+	    /* Something wrong: Fall back to singlebyte matching. */
ce426f
+	    goto free_and_try_singlebyte;
ce426f
 	  if (__builtin_expect (n >= (size_t) -1 / sizeof (wchar_t), 0))
ce426f
 	    {
ce426f
 	      free (wpattern_malloc);
ce426f
@@ -450,6 +439,10 @@ fnmatch (pattern, string, flags)
ce426f
       free (wpattern_malloc);
ce426f
 
ce426f
       return res;
ce426f
+      free_and_try_singlebyte:
ce426f
+	free(wpattern_malloc);
ce426f
+      try_singlebyte:
ce426f
+	pattern = orig_pattern;
ce426f
     }
ce426f
 # endif  /* mbstate_t and mbsrtowcs or _LIBC.  */
ce426f