arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh819430.patch

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