From b5bf4d72d917538b415d917959f41c8dd7478798 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 15 Aug 2017 00:54:16 +0000 Subject: MFC r322368, r322371: fnmatch(3): improve POSIX conformance. In a recent interpretation[1], "\\" shall return a non-zero value (indicating either no match or an error). The fix involves a change over r254091 and now the behavior matches the Sun/IBM/HP closed source implementations and also likely musl libc. Submitted by: Joerg Schilling [1] http://austingroupbugs.net/view.php?id=806 --- lib/libc/gen/fnmatch.c | 3 ++- lib/libc/tests/gen/fnmatch_testcases.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c index 65efe20..d18e345 100644 --- a/lib/libc/gen/fnmatch.c +++ b/lib/libc/gen/fnmatch.c @@ -184,7 +184,8 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart, if (!(flags & FNM_NOESCAPE)) { pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs); - if (pclen == (size_t)-1 || pclen == (size_t)-2) + if (pclen == 0 || pclen == (size_t)-1 || + pclen == (size_t)-2) return (FNM_NOMATCH); pattern += pclen; } diff --git a/lib/libc/tests/gen/fnmatch_testcases.h b/lib/libc/tests/gen/fnmatch_testcases.h index 537011f..996e13c 100644 --- a/lib/libc/tests/gen/fnmatch_testcases.h +++ b/lib/libc/tests/gen/fnmatch_testcases.h @@ -131,7 +131,7 @@ struct testcase { { "\\(", "\\(", 0, FNM_NOMATCH }, { "\\a", "\\a", 0, FNM_NOMATCH }, { "\\", "\\", 0, FNM_NOMATCH }, - { "\\", "", 0, 0 }, + { "\\", "", 0, FNM_NOMATCH }, { "\\*", "\\*", FNM_NOESCAPE, 0 }, { "\\?", "\\?", FNM_NOESCAPE, 0 }, { "\\", "\\", FNM_NOESCAPE, 0 }, -- cgit v1.1