Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gen Fix fnmatch issues according to POSIX.
details: https://anonhg.NetBSD.org/src/rev/bb9ed5375a7d
branches: trunk
changeset: 332968:bb9ed5375a7d
user: christos <christos%NetBSD.org@localhost>
date: Sun Oct 12 22:32:33 2014 +0000
description:
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.
diffstat:
lib/libc/gen/fnmatch.c | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diffs (65 lines):
diff -r dc5d88b7a7b8 -r bb9ed5375a7d lib/libc/gen/fnmatch.c
--- a/lib/libc/gen/fnmatch.c Sun Oct 12 20:05:50 2014 +0000
+++ b/lib/libc/gen/fnmatch.c Sun Oct 12 22:32:33 2014 +0000
@@ -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 @@
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 @@
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 @@
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 @@
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 '\\':
Home |
Main Index |
Thread Index |
Old Index