From owner-freebsd-bugs@FreeBSD.ORG Thu Apr 30 12:00:21 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7AE8310656BA for ; Thu, 30 Apr 2009 12:00:21 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 4BAAC8FC0A for ; Thu, 30 Apr 2009 12:00:21 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n3UC0Lgq008212 for ; Thu, 30 Apr 2009 12:00:21 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n3UC0Kg8008205; Thu, 30 Apr 2009 12:00:21 GMT (envelope-from gnats) Date: Thu, 30 Apr 2009 12:00:21 GMT Message-Id: <200904301200.n3UC0Kg8008205@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/116074: [libc] fnmatch() does not handle FNM_PERIOD correctly X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2009 12:00:23 -0000 The following reply was made to PR bin/116074; it has been noted by GNATS. From: Jilles Tjoelker 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--