The following reply was made to PR bin/116074; it has been noted by GNATS.
From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, cejkar@fit.vutbr.cz
Cc:
Subject: Re: bin/116074: [libc] fnmatch() does not handle FNM_PERIOD
correctly
Date: Thu, 30 Apr 2009 13:52:18 +0200
--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
A possible patch: http://www.stack.nl/~jilles/unix/fnmatch-period.patch
This passes the original stringstart along with recursive calls.
I suppose the recursion could be removed entirely and replaced by
backtracking (to the last asterisk seen), like ircd's match function
does. It is not necessary to backtrack to any other asterisk. Note that
this is only possible because the asterisk can match arbitrarily many of
any character.
--
Jilles Tjoelker
--rwEMma7ioTxnRzrJ
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="fnmatch-period.patch"
--- src/lib/libc/gen/fnmatch.c.orig 2008-03-18 23:15:53.000000000 +0100
+++ src/lib/libc/gen/fnmatch.c 2009-04-26 22:41:18.000000000 +0200
@@ -67,7 +67,8 @@
#define RANGE_ERROR (-1)
static int rangematch(const char *, wchar_t, int, char **, mbstate_t *);
-static int fnmatch1(const char *, const char *, int, mbstate_t, mbstate_t);
+static int fnmatch1(const char *, const char *, const char *, int, mbstate_t,
+ mbstate_t);
int
fnmatch(pattern, string, flags)
@@ -76,22 +77,21 @@
{
static const mbstate_t initial;
- return (fnmatch1(pattern, string, flags, initial, initial));
+ return (fnmatch1(pattern, string, string, flags, initial, initial));
}
static int
-fnmatch1(pattern, string, flags, patmbs, strmbs)
- const char *pattern, *string;
+fnmatch1(pattern, string, stringstart, flags, patmbs, strmbs)
+ const char *pattern, *string, *stringstart;
int flags;
mbstate_t patmbs, strmbs;
{
- const char *stringstart;
char *newp;
char c;
wchar_t pc, sc;
size_t pclen, sclen;
- for (stringstart = string;;) {
+ for (;;) {
pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs);
if (pclen == (size_t)-1 || pclen == (size_t)-2)
return (FNM_NOMATCH);
@@ -145,8 +145,8 @@
/* General case, use recursion. */
while (sc != EOS) {
- if (!fnmatch1(pattern, string,
- flags & ~FNM_PERIOD, patmbs, strmbs))
+ if (!fnmatch1(pattern, string, stringstart,
+ flags, patmbs, strmbs))
return (0);
sclen = mbrtowc(&sc, string, MB_LEN_MAX,
&strmbs);
--rwEMma7ioTxnRzrJ--
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscribe@freebsd.org"