|
Carlos O'Donell |
0e17ea2 |
Short description: fnmatch() fails with MBCS.
|
|
Carlos O'Donell |
0e17ea2 |
Author(s): Fedora glibc team <glibc@lists.fedoraproject.org>
|
|
Carlos O'Donell |
0e17ea2 |
Origin: PATCH
|
|
Carlos O'Donell |
0e17ea2 |
Bug-RHEL: #819430, #826149, #826151
|
|
Carlos O'Donell |
0e17ea2 |
Bug-Upstream: #14185
|
|
Carlos O'Donell |
0e17ea2 |
Upstream status: not-submitted
|
|
Carlos O'Donell |
0e17ea2 |
|
|
Carlos O'Donell |
0e17ea2 |
fnmatch() fails when '*' wildcard is applied on the file name
|
|
Carlos O'Donell |
0e17ea2 |
containing multi-byte character(s)
|
|
Carlos O'Donell |
0e17ea2 |
|
|
Carlos O'Donell |
0e17ea2 |
This needs to be reviewed thoroughly and go upstream with a
|
|
Carlos O'Donell |
0e17ea2 |
new test case.
|
|
Carlos O'Donell |
0e17ea2 |
|
|
|
200aebf |
diff -Nrup a/posix/fnmatch.c b/posix/fnmatch.c
|
|
|
200aebf |
--- a/posix/fnmatch.c 2012-01-01 07:16:32.000000000 -0500
|
|
|
200aebf |
+++ b/posix/fnmatch.c 2012-05-23 14:14:29.099461189 -0400
|
|
|
200aebf |
@@ -333,6 +333,7 @@ fnmatch (pattern, string, flags)
|
|
|
200aebf |
# if HANDLE_MULTIBYTE
|
|
|
200aebf |
if (__builtin_expect (MB_CUR_MAX, 1) != 1)
|
|
|
200aebf |
{
|
|
|
200aebf |
+ const char *orig_pattern = pattern;
|
|
|
200aebf |
mbstate_t ps;
|
|
|
200aebf |
size_t n;
|
|
|
200aebf |
const char *p;
|
|
|
200aebf |
@@ -356,10 +357,8 @@ fnmatch (pattern, string, flags)
|
|
|
200aebf |
alloca_used);
|
|
|
200aebf |
n = mbsrtowcs (wpattern, &p, n + 1, &ps);
|
|
Siddhesh Poyarekar |
372014c |
if (__glibc_unlikely (n == (size_t) -1))
|
|
|
200aebf |
- /* Something wrong.
|
|
|
200aebf |
- XXX Do we have to set `errno' to something which mbsrtows hasn't
|
|
|
200aebf |
- already done? */
|
|
|
200aebf |
- return -1;
|
|
|
200aebf |
+ /* Something wrong: Fall back to single byte matching. */
|
|
|
200aebf |
+ goto try_singlebyte;
|
|
|
200aebf |
if (p)
|
|
|
200aebf |
{
|
|
|
200aebf |
memset (&ps, '\0', sizeof (ps));
|
|
|
200aebf |
@@ -371,10 +370,8 @@ fnmatch (pattern, string, flags)
|
|
|
200aebf |
prepare_wpattern:
|
|
|
200aebf |
n = mbsrtowcs (NULL, &pattern, 0, &ps);
|
|
Siddhesh Poyarekar |
372014c |
if (__glibc_unlikely (n == (size_t) -1))
|
|
|
200aebf |
- /* Something wrong.
|
|
|
200aebf |
- XXX Do we have to set `errno' to something which mbsrtows hasn't
|
|
|
200aebf |
- already done? */
|
|
|
200aebf |
- return -1;
|
|
|
200aebf |
+ /*Something wrong: Fall back to single byte matching. */
|
|
|
200aebf |
+ goto try_singlebyte;
|
|
Siddhesh Poyarekar |
372014c |
if (__glibc_unlikely (n >= (size_t) -1 / sizeof (wchar_t)))
|
|
|
200aebf |
{
|
|
|
200aebf |
__set_errno (ENOMEM);
|
|
|
200aebf |
@@ -401,14 +398,8 @@ fnmatch (pattern, string, flags)
|
|
|
200aebf |
alloca_used);
|
|
|
200aebf |
n = mbsrtowcs (wstring, &p, n + 1, &ps);
|
|
Siddhesh Poyarekar |
372014c |
if (__glibc_unlikely (n == (size_t) -1))
|
|
|
200aebf |
- {
|
|
|
200aebf |
- /* Something wrong.
|
|
|
200aebf |
- XXX Do we have to set `errno' to something which
|
|
|
200aebf |
- mbsrtows hasn't already done? */
|
|
|
200aebf |
- free_return:
|
|
|
200aebf |
- free (wpattern_malloc);
|
|
|
200aebf |
- return -1;
|
|
|
200aebf |
- }
|
|
|
200aebf |
+ /* Something wrong: Fall back to single byte matching. */
|
|
|
200aebf |
+ goto free_and_try_singlebyte;
|
|
|
200aebf |
if (p)
|
|
|
200aebf |
{
|
|
|
200aebf |
memset (&ps, '\0', sizeof (ps));
|
|
|
200aebf |
@@ -420,10 +411,8 @@ fnmatch (pattern, string, flags)
|
|
|
200aebf |
prepare_wstring:
|
|
|
200aebf |
n = mbsrtowcs (NULL, &string, 0, &ps);
|
|
Siddhesh Poyarekar |
372014c |
if (__glibc_unlikely (n == (size_t) -1))
|
|
|
200aebf |
- /* Something wrong.
|
|
|
200aebf |
- XXX Do we have to set `errno' to something which mbsrtows hasn't
|
|
|
200aebf |
- already done? */
|
|
|
200aebf |
- goto free_return;
|
|
|
200aebf |
+ /* Something wrong: Fall back to singlebyte matching. */
|
|
|
200aebf |
+ goto free_and_try_singlebyte;
|
|
Siddhesh Poyarekar |
372014c |
if (__glibc_unlikely (n >= (size_t) -1 / sizeof (wchar_t)))
|
|
|
200aebf |
{
|
|
|
200aebf |
free (wpattern_malloc);
|
|
|
200aebf |
@@ -450,6 +439,10 @@ fnmatch (pattern, string, flags)
|
|
|
200aebf |
free (wpattern_malloc);
|
|
|
200aebf |
|
|
|
200aebf |
return res;
|
|
|
200aebf |
+ free_and_try_singlebyte:
|
|
|
200aebf |
+ free(wpattern_malloc);
|
|
|
200aebf |
+ try_singlebyte:
|
|
|
200aebf |
+ pattern = orig_pattern;
|
|
|
200aebf |
}
|
|
|
200aebf |
# endif /* mbstate_t and mbsrtowcs or _LIBC. */
|
|
|
200aebf |
|