]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix handling of collating symbols in fnmatch (bug 26620)
authorAndreas Schwab <schwab@suse.de>
Wed, 16 Sep 2020 10:41:14 +0000 (12:41 +0200)
committerAndreas Schwab <schwab@suse.de>
Wed, 16 Sep 2020 12:45:10 +0000 (14:45 +0200)
The variable idx contains the index into the extra array, whereas wextra
points into the extra array at this index, containing the length of the
following collating sequence in the wide character representation.

posix/Makefile
posix/fnmatch_loop.c
posix/tst-fnmatch6.c [new file with mode: 0644]

index 605ddbade863d003b54dd7ffa2d79442d5d1846b..83c4d572310cdbb9033b305123002f2cb1eb99bf 100644 (file)
@@ -96,7 +96,7 @@ tests         := test-errno tstgetopt testfnm runtests runptests \
                   bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \
                   tst-pathconf tst-rxspencer-no-utf8 \
                   tst-fnmatch3 bug-regex36 \
-                  tst-fnmatch4 tst-fnmatch5 \
+                  tst-fnmatch4 tst-fnmatch5 tst-fnmatch6 \
                   tst-posix_spawn-fd tst-posix_spawn-setsid \
                   tst-posix_fadvise tst-posix_fadvise64 \
                   tst-sysconf-empty-chroot tst-glob_symlinks tst-fexecve \
@@ -197,6 +197,7 @@ $(objpfx)bug-regex35.out: $(gen-locales)
 $(objpfx)tst-fnmatch.out: $(gen-locales)
 $(objpfx)tst-fnmatch4.out: $(gen-locales)
 $(objpfx)tst-fnmatch5.out: $(gen-locales)
+$(objpfx)tst-fnmatch6.out: $(gen-locales)
 $(objpfx)tst-regex.out: $(gen-locales)
 $(objpfx)tst-regex2.out: $(gen-locales)
 $(objpfx)tst-regexloc.out: $(gen-locales)
index 8ead4dc7b964c2e334cce7022b28465b64a83f98..0f890d478294688e3288ef1713d1f548e7afcdf3 100644 (file)
@@ -564,7 +564,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
                                /* Get the collation sequence value.  */
                                is_seqval = 1;
 # if WIDE_CHAR_VERSION
-                               cold = wextra[1 + wextra[idx]];
+                               cold = wextra[1 + wextra[0]];
 # else
                                idx += 1 + extra[idx];
                                /* Adjust for the alignment.  */
@@ -738,7 +738,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
                                    /* Get the collation sequence value.  */
                                    is_seqval = 1;
 # if WIDE_CHAR_VERSION
-                                   cend = wextra[1 + wextra[idx]];
+                                   cend = wextra[1 + wextra[0]];
 # else
                                    idx += 1 + extra[idx];
                                    /* Adjust for the alignment.  */
diff --git a/posix/tst-fnmatch6.c b/posix/tst-fnmatch6.c
new file mode 100644 (file)
index 0000000..c255702
--- /dev/null
@@ -0,0 +1,37 @@
+/* Test for fnmatch handling of collating symbols (bug 26620)
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <fnmatch.h>
+#include <locale.h>
+#include <support/check.h>
+#include <support/support.h>
+
+static int
+do_test (void)
+{
+  xsetlocale (LC_ALL, "en_US.UTF-8");
+  /* From iso14651_t1_common:
+     collating-element <U004C_00B7> from "<U004C><U00B7>"
+     % decomposition of LATIN CAPITAL LETTER L WITH MIDDLE DOT */
+  TEST_VERIFY (fnmatch ("[[.L\xc2\xb7.]]", ".", 0) != 0);
+  TEST_VERIFY (fnmatch ("[[.L\xc2\xb7.]]", "L\xc2\xb7", 0) == 0);
+
+  return 0;
+}
+
+#include <support/test-driver.c>