Module Name: src
Committed By: christos
Date: Sun Oct 12 22:32:33 UTC 2014
Modified Files:
src/lib/libc/gen: fnmatch.c
Log Message:
Fix fnmatch issues according to POSIX.
http://pubs.opengroup.org/onlinepubs/009695399/utilities/\
xcu_chap02.html#tag_02_13_01
1. A [...] pattern containing a slash is not a pattern; the [ ]'s become regular
characters
2. A [] or a [!] is not an empty pattern, why would it? The first would never
match and the second would always match which makes it equivalent to ?
In those cases the ] is taken as a literal character and does not have
special meaning.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/gen/fnmatch.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/gen/fnmatch.c
diff -u src/lib/libc/gen/fnmatch.c:1.25 src/lib/libc/gen/fnmatch.c:1.26
--- src/lib/libc/gen/fnmatch.c:1.25 Sun Mar 25 12:31:23 2012
+++ src/lib/libc/gen/fnmatch.c Sun Oct 12 18:32:33 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: fnmatch.c,v 1.25 2012/03/25 16:31:23 christos Exp $ */
+/* $NetBSD: fnmatch.c,v 1.26 2014/10/12 22:32:33 christos Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#else
-__RCSID("$NetBSD: fnmatch.c,v 1.25 2012/03/25 16:31:23 christos Exp $");
+__RCSID("$NetBSD: fnmatch.c,v 1.26 2014/10/12 22:32:33 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -73,7 +73,7 @@ foldcase(int ch, int flags)
static const char *
rangematch(const char *pattern, int test, int flags)
{
- int negate, ok;
+ int negate, ok, need;
char c, c2;
_DIAGASSERT(pattern != NULL);
@@ -88,7 +88,11 @@ rangematch(const char *pattern, int test
if ((negate = (*pattern == '!' || *pattern == '^')) != 0)
++pattern;
- for (ok = 0; (c = FOLDCASE(*pattern++, flags)) != ']';) {
+ need = 1;
+ for (ok = 0; (c = FOLDCASE(*pattern++, flags)) != ']' || need;) {
+ need = 0;
+ if (c == '/')
+ return (void *)-1;
if (c == '\\' && !(flags & FNM_NOESCAPE))
c = FOLDCASE(*pattern++, flags);
if (c == EOS)
@@ -113,7 +117,7 @@ rangematch(const char *pattern, int test
static int
fnmatchx(const char *pattern, const char *string, int flags, size_t recursion)
{
- const char *stringstart;
+ const char *stringstart, *r;
char c, test;
_DIAGASSERT(pattern != NULL);
@@ -184,9 +188,14 @@ fnmatchx(const char *pattern, const char
return FNM_NOMATCH;
if (*string == '/' && flags & FNM_PATHNAME)
return FNM_NOMATCH;
- if ((pattern = rangematch(pattern,
+ if ((r = rangematch(pattern,
FOLDCASE(*string, flags), flags)) == NULL)
return FNM_NOMATCH;
+ if (r == (void *)-1) {
+ if (*string != '[')
+ return FNM_NOMATCH;
+ } else
+ pattern = r;
++string;
break;
case '\\':