From 063ead34ac0773b00d1f16e53df07c77a08ec370 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 10 Oct 2017 21:04:40 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.freebsd.org/base/stable/10@324505 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libc/gen/fnmatch.c | 3 ++- lib/libc/tests/gen/fnmatch_testcases.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c index db154948c..aa8b252b6 100644 --- a/lib/libc/gen/fnmatch.c +++ b/lib/libc/gen/fnmatch.c @@ -188,7 +188,8 @@ fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs) 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 537011fc3..996e13c77 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 }, -- 2.42.0