From d5c86249fffa98513fd74a424c67c49c3d1bb221 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 23 Jul 2023 15:26:28 +0200 Subject: [PATCH] fnmatch: Work around bugs on FreeBSD, NetBSD, Solaris, Cygwin, Android. * m4/fnmatch.m4 (gl_FUNC_FNMATCH_POSIX): Add three more test cases to the test program. Reorganize its return values. * tests/test-fnmatch.c (main): Reflect the changes done in fnmatch.m4. * doc/posix-functions/fnmatch.texi: Move the corresponding bug descriptions to the "fixed by Gnulib" section. --- ChangeLog | 9 +++ doc/posix-functions/fnmatch.texi | 129 +++++++++++++++---------------- m4/fnmatch.m4 | 77 ++++++++++++------ tests/test-fnmatch.c | 10 ++- 4 files changed, 132 insertions(+), 93 deletions(-) diff --git a/ChangeLog b/ChangeLog index c0ca5efceb..14f4b4eda0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-07-23 Bruno Haible + + fnmatch: Work around bugs on FreeBSD, NetBSD, Solaris, Cygwin, Android. + * m4/fnmatch.m4 (gl_FUNC_FNMATCH_POSIX): Add three more test cases to + the test program. Reorganize its return values. + * tests/test-fnmatch.c (main): Reflect the changes done in fnmatch.m4. + * doc/posix-functions/fnmatch.texi: Move the corresponding bug + descriptions to the "fixed by Gnulib" section. + 2023-07-23 Bruno Haible fnmatch, fnmatch-gnu: Document known bugs. diff --git a/doc/posix-functions/fnmatch.texi b/doc/posix-functions/fnmatch.texi index 3211cc892a..69560c33a6 100644 --- a/doc/posix-functions/fnmatch.texi +++ b/doc/posix-functions/fnmatch.texi @@ -27,6 +27,64 @@ Portability problems fixed by either Gnulib module @code{fnmatch} or @code{fnmat This function is missing on some platforms: mingw, MSVC 14. @item +The @code{"?"} pattern character fails to match characters outside the +single-byte range on some platforms: +@c Failing test cases: +@c fnmatch ("x?y", "x\303\274y", 0) == 0 +@c fnmatch ("x?y", "x\303\237y", 0) == 0 +@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0 +@c fnmatch ("x?y", "x\306\374y", 0) == 0 +@c fnmatch ("x?y", "x\313\334y", 0) == 0 +@c fnmatch ("x?y", "x\270\354y", 0) == 0 +@c fnmatch ("x?y", "x\250\271y", 0) == 0 +@c fnmatch ("x?y", "x\201\060\211\070y", 0) == 0 +@c fnmatch ("x?y", "x\224\071\375\067y", 0) == 0 +NetBSD 9.3, +@c Failing test cases: +@c fnmatch ("x?y", "x\303\274y", 0) == 0 +@c fnmatch ("x?y", "x\303\237y", 0) == 0 +@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0 +Android 13. +@item +In the pattern, negated character ranges (such as @code{[!a-z]}) are not +supported on some platforms: +@c Failing test cases: +@c fnmatch ("[!a-z]", "", 0) == FNM_NOMATCH +Solaris 11.4. +@item +In the pattern, character classes (such as @code{[:alnum:]}) inside +bracket expressions are not supported on some platforms: +@c Failing test cases: +@c fnmatch ("[[:alnum:]]", "a", 0) == 0 +@c etc. +FreeBSD 13.2, NetBSD 9.3, Cygwin 3.4.6. +@item +In the pattern, character classes (such as @code{[:alnum:]}) inside +bracket expressions fail to match characters outside the single-byte +range on some platforms: +@c Failing test cases: +@c fnmatch ("x[[:alnum:]]y", "x\305\201y", 0) == 0 +@c fnmatch ("x[[:alnum:]]y", "x\360\220\214\260y", 0) == 0 +@c fnmatch ("x[[:alpha:]]y", "x\305\201y", 0) == 0 +@c fnmatch ("x[[:alpha:]]y", "x\360\220\214\260y", 0) == 0 +@c fnmatch ("x[[:graph:]]y", "x\302\270y", 0) == 0 +@c fnmatch ("x[[:graph:]]y", "x\360\240\200\200y", 0) == 0 +@c fnmatch ("x[[:lower:]]y", "x\303\277y", 0) == 0 +@c fnmatch ("x[[:lower:]]y", "x\360\220\221\201y", 0) == 0 +@c fnmatch ("x[[:print:]]y", "x\302\270y", 0) == 0 +@c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0 +@c fnmatch ("x[[:punct:]]y", "x\302\277y", 0) == 0 +@c fnmatch ("x[[:space:]]y", "x\343\200\200y", 0) == 0 +@c fnmatch ("x[[:upper:]]y", "x\320\251y", 0) == 0 +@c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0 +Android 13. +@item +The character class @code{[:cntrl:]} matches the empty string +on some platforms: +@c Failing test cases: +@c fnmatch ("[[:cntrl:]]", "", 0) == FNM_NOMATCH +Solaris 11.4. +@item Ranges that start or end with a backslash don't work right on some platforms: @c https://sourceware.org/bugzilla/show_bug.cgi?id=361 glibc 2.3.3. @@ -46,7 +104,11 @@ glibc 2.12, @c fnmatch ("[", "[", 0) == 0 @c fnmatch ("[", "]", 0) == FNM_NOMATCH @c fnmatch ("[/b", "[/b", 0) == 0 -macOS 12.5. +macOS 12.5, +@c Failing test cases: +@c fnmatch ("[", "[", 0) == 0 +@c fnmatch ("[/-/]", "/", 0) == 0 +NetBSD 9.3. @end itemize Portability problems fixed by Gnulib module @code{fnmatch-gnu}: @@ -88,25 +150,6 @@ Portability problems not fixed by Gnulib: @itemize @item The @code{"?"} pattern character fails to match characters outside the -single-byte range on some platforms: -@c Failing test cases: -@c fnmatch ("x?y", "x\303\274y", 0) == 0 -@c fnmatch ("x?y", "x\303\237y", 0) == 0 -@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0 -@c fnmatch ("x?y", "x\306\374y", 0) == 0 -@c fnmatch ("x?y", "x\313\334y", 0) == 0 -@c fnmatch ("x?y", "x\270\354y", 0) == 0 -@c fnmatch ("x?y", "x\250\271y", 0) == 0 -@c fnmatch ("x?y", "x\201\060\211\070y", 0) == 0 -@c fnmatch ("x?y", "x\224\071\375\067y", 0) == 0 -NetBSD 9.3, -@c Failing test cases: -@c fnmatch ("x?y", "x\303\274y", 0) == 0 -@c fnmatch ("x?y", "x\303\237y", 0) == 0 -@c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0 -Android 13. -@item -The @code{"?"} pattern character fails to match characters outside the Unicode BMP on some platforms: @c Failing test cases: @c fnmatch ("x?y", "x\360\237\230\213y", 0) == 0 @@ -130,52 +173,6 @@ MSVC, @c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0 @c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0 32-bit AIX. -@item -In the pattern, negated character ranges (such as @code{[!a-z]}) are not -supported on some platforms: -@c Failing test cases: -@c fnmatch ("[!a-z]", "", 0) == FNM_NOMATCH -Solaris 11.4. -@item -In the pattern, character classes (such as @code{[:alnum:]}) inside -bracket expressions are not supported on some platforms: -@c Failing test cases: -@c fnmatch ("[[:alnum:]]", "a", 0) == 0 -@c etc. -FreeBSD 13.2, NetBSD 9.3, Cygwin 2.9.0. -@item -In the pattern, character classes (such as @code{[:alnum:]}) inside -bracket expressions fail to match characters outside the single-byte -range on some platforms: -@c Failing test cases: -@c fnmatch ("x[[:alnum:]]y", "x\305\201y", 0) == 0 -@c fnmatch ("x[[:alnum:]]y", "x\360\220\214\260y", 0) == 0 -@c fnmatch ("x[[:alpha:]]y", "x\305\201y", 0) == 0 -@c fnmatch ("x[[:alpha:]]y", "x\360\220\214\260y", 0) == 0 -@c fnmatch ("x[[:graph:]]y", "x\302\270y", 0) == 0 -@c fnmatch ("x[[:graph:]]y", "x\360\240\200\200y", 0) == 0 -@c fnmatch ("x[[:lower:]]y", "x\303\277y", 0) == 0 -@c fnmatch ("x[[:lower:]]y", "x\360\220\221\201y", 0) == 0 -@c fnmatch ("x[[:print:]]y", "x\302\270y", 0) == 0 -@c fnmatch ("x[[:print:]]y", "x\360\240\200\200y", 0) == 0 -@c fnmatch ("x[[:punct:]]y", "x\302\277y", 0) == 0 -@c fnmatch ("x[[:space:]]y", "x\343\200\200y", 0) == 0 -@c fnmatch ("x[[:upper:]]y", "x\320\251y", 0) == 0 -@c fnmatch ("x[[:upper:]]y", "x\360\220\220\231y", 0) == 0 -Android 13. -@item -The character class @code{[:cntrl:]} matches the empty string -on some platforms: -@c Failing test cases: -@c fnmatch ("[[:cntrl:]]", "", 0) == FNM_NOMATCH -Solaris 11.4. -@item -In the pattern, an opening bracket without closing bracket does not match -a literal @code{'['} on some platforms: -@c Failing test cases: -@c fnmatch ("[", "[", 0) == 0 -@c fnmatch ("[/-/]", "/", 0) == 0 -NetBSD 9.3. @end itemize Note: Gnulib's replacement function has some limitations: diff --git a/m4/fnmatch.m4 b/m4/fnmatch.m4 index 895db13a2d..eba70de2bc 100644 --- a/m4/fnmatch.m4 +++ b/m4/fnmatch.m4 @@ -1,4 +1,4 @@ -# Check for fnmatch - serial 16. -*- coding: utf-8 -*- +# Check for fnmatch - serial 17 -*- coding: utf-8 -*- # Copyright (C) 2000-2007, 2009-2023 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -40,6 +40,8 @@ AC_DEFUN([gl_FUNC_FNMATCH_POSIX], AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#include + #include + #include static int y (char const *pattern, char const *string, int flags) { @@ -60,60 +62,85 @@ AC_DEFUN([gl_FUNC_FNMATCH_POSIX], static char const bs_1[] = { '\\\\' - 1, 0 }; static char const bs01[] = { '\\\\' + 1, 0 }; int result = 0; + /* ==== Start of tests in the "C" locale ==== */ + /* These are sanity checks. They all succeed on current platforms. */ if (!n ("a*", "", 0)) return 1; if (!y ("a*", "abc", 0)) return 1; - if (!y ("[/b", "[/b", 0)) /*"]]"*/ /* glibc Bugzilla bug 12378 */ - return 1; if (!n ("d*/*1", "d/s/1", FNM_PATHNAME)) - return 2; + return 1; if (!y ("a\\\\bc", "abc", 0)) - return 3; + return 1; if (!n ("a\\\\bc", "abc", FNM_NOESCAPE)) - return 3; + return 1; if (!y ("*x", ".x", 0)) - return 4; + return 1; if (!n ("*x", ".x", FNM_PERIOD)) - return 4; + return 1; + /* glibc bug + exists in glibc 2.3.3, fixed in glibc 2.5. */ if (!y (Apat, "\\\\", 0)) - return 5; + result |= 2; if (!y (Apat, "A", 0)) - return 5; + result |= 2; if (!y (apat, "\\\\", 0)) - return 5; + result |= 2; if (!y (apat, "a", 0)) - return 5; + result |= 2; if (!(n (Apat, A_1, 0) == ('A' < '\\\\'))) - return 5; + result |= 2; if (!(n (apat, a_1, 0) == ('a' < '\\\\'))) - return 5; + result |= 2; if (!(y (Apat, A01, 0) == ('A' < '\\\\'))) - return 5; + result |= 2; if (!(y (apat, a01, 0) == ('a' < '\\\\'))) - return 5; + result |= 2; if (!(y (Apat, bs_1, 0) == ('A' < '\\\\'))) - return 5; + result |= 2; if (!(y (apat, bs_1, 0) == ('a' < '\\\\'))) - return 5; + result |= 2; if (!(n (Apat, bs01, 0) == ('A' < '\\\\'))) - return 5; + result |= 2; if (!(n (apat, bs01, 0) == ('a' < '\\\\'))) - return 5; - $gl_fnmatch_gnu_start - if (!y ("xxXX", "xXxX", FNM_CASEFOLD)) + result |= 2; + /* glibc bug + exists in glibc 2.12, fixed in glibc 2.13. */ + if (!y ("[/b", "[/b", 0)) /*"]]"*/ + result |= 4; + /* This test fails on FreeBSD 13.2, NetBSD 9.3, Cygwin 3.4.6. */ + if (!y ("[[:alnum:]]", "a", 0)) result |= 8; + $gl_fnmatch_gnu_start /* ==== Start of GNU extensions tests ==== */ + /* Sanity checks, mainly to check the presence of the FNM_* macros. */ + if (!y ("xxXX", "xXxX", FNM_CASEFOLD)) + result |= 64; if (!y ("a++(x|yy)b", "a+xyyyyxb", FNM_EXTMATCH)) - result |= 16; + result |= 64; if (!n ("d*/*1", "d/s/1", FNM_FILE_NAME)) - result |= 32; + result |= 64; if (!y ("*", "x", FNM_FILE_NAME | FNM_LEADING_DIR)) result |= 64; if (!y ("x*", "x/y/z", FNM_FILE_NAME | FNM_LEADING_DIR)) result |= 64; if (!y ("*c*", "c/x", FNM_FILE_NAME | FNM_LEADING_DIR)) result |= 64; - $gl_fnmatch_gnu_end + $gl_fnmatch_gnu_end /* ==== End of GNU extensions tests ==== */ + /* ==== End of tests in the "C" locale ==== */ + /* ==== Start of tests that require a specific locale ==== */ + /* This test fails on Solaris 11.4. */ + if (setlocale (LC_ALL, "en_US.UTF-8") != NULL) + { + if (!n ("[!a-z]", "", 0)) + result |= 16; + } + /* This test fails on NetBSD 9.3, Android 13. */ + if (setlocale (LC_ALL, "C.UTF-8") != NULL) + { + if (!y ("x?y", "x\\303\\274y", 0)) + result |= 32; + } + /* ==== End of tests that require a specific locale ==== */ return result; ]])], [eval "$gl_fnmatch_cache_var=yes"], diff --git a/tests/test-fnmatch.c b/tests/test-fnmatch.c index 22c0db150e..5d5535fda5 100644 --- a/tests/test-fnmatch.c +++ b/tests/test-fnmatch.c @@ -564,10 +564,9 @@ main (int argc, char *argv[]) static char const a01[] = { 'a' + 1, 0 }; static char const bs_1[] = { '\\' - 1, 0 }; static char const bs01[] = { '\\' + 1, 0 }; + /* These are sanity checks. They all succeed on current platforms. */ ASSERT (fnmatch ("a*", "", 0) == FNM_NOMATCH); ASSERT (fnmatch ("a*", "abc", 0) == 0); - /* */ - ASSERT (fnmatch ("[/b", "[/b", 0) == 0); ASSERT (fnmatch ("d*/*1", "d/s/1", FNM_PATHNAME) == FNM_NOMATCH); ASSERT (fnmatch ("a\\bc", "abc", 0) == 0); ASSERT (fnmatch ("a\\bc", "abc", FNM_NOESCAPE) == FNM_NOMATCH); @@ -575,6 +574,8 @@ main (int argc, char *argv[]) ASSERT (fnmatch ("*x", ".x", FNM_PERIOD) == FNM_NOMATCH); if (argc == 1 || strcmp (argv[1], "1") == 0) { + /* glibc bug + exists in glibc 2.3.3, fixed in glibc 2.5. */ ASSERT (fnmatch (Apat, "\\", 0) == 0); ASSERT (fnmatch (Apat, "A", 0) == 0); ASSERT (fnmatch (apat, "\\", 0) == 0); @@ -588,6 +589,11 @@ main (int argc, char *argv[]) ASSERT (fnmatch (Apat, bs01, 0) == ('A' < '\\' ? FNM_NOMATCH : 0)); ASSERT (fnmatch (apat, bs01, 0) == ('a' < '\\' ? FNM_NOMATCH : 0)); } + /* glibc bug + exists in glibc 2.12, fixed in glibc 2.13. */ + ASSERT (fnmatch ("[/b", "[/b", 0) == 0); + /* This test fails on FreeBSD 13.2, NetBSD 9.3, Cygwin 3.4.6. */ + ASSERT (fnmatch ("[[:alnum:]]", "a", 0) == 0); #if GNULIB_FNMATCH_GNU && defined FNM_CASEFOLD ASSERT (fnmatch ("xxXX", "xXxX", FNM_CASEFOLD) == 0); #endif -- 2.39.5