From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14459 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] glob: implement GLOB_NOMAGIC Date: Fri, 26 Jul 2019 22:39:51 -0400 Message-ID: <20190727023951.GP1506@brightrain.aerifal.cx> References: <20190726234847.12321-1-ismael@iodev.co.uk> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="158530"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14475-gllmg-musl=m.gmane.org@lists.openwall.com Sat Jul 27 04:40:09 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hrCcy-000f88-I0 for gllmg-musl@m.gmane.org; Sat, 27 Jul 2019 04:40:08 +0200 Original-Received: (qmail 29920 invoked by uid 550); 27 Jul 2019 02:40:06 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 29902 invoked from network); 27 Jul 2019 02:40:05 -0000 Content-Disposition: inline In-Reply-To: <20190726234847.12321-1-ismael@iodev.co.uk> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14459 Archived-At: On Sat, Jul 27, 2019 at 01:48:47AM +0200, Ismael Luceno wrote: > Signed-off-by: Ismael Luceno > --- > include/glob.h | 1 + > src/regex/glob.c | 13 +++++++++---- > 2 files changed, 10 insertions(+), 4 deletions(-) > > diff --git a/include/glob.h b/include/glob.h > index 4a562a206d52..0ff70bdfeef2 100644 > --- a/include/glob.h > +++ b/include/glob.h > @@ -31,6 +31,7 @@ void globfree(glob_t *); > #define GLOB_NOESCAPE 0x40 > #define GLOB_PERIOD 0x80 > > +#define GLOB_NOMAGIC 0x0800 > #define GLOB_TILDE 0x1000 > #define GLOB_TILDE_CHECK 0x4000 > > diff --git a/src/regex/glob.c b/src/regex/glob.c > index 58248675c203..0ccd9759c5e7 100644 > --- a/src/regex/glob.c > +++ b/src/regex/glob.c > @@ -253,13 +253,18 @@ int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, i > > for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++); > if (!cnt) { > + size_t len; > if (flags & GLOB_NOCHECK) { > - tail = &head; > - if (append(&tail, pat, strlen(pat), 0)) > - return GLOB_NOSPACE; > - cnt++; > + len = strlen(pat); > + } else if (flags & GLOB_NOMAGIC) { > + len = strcspn(pat, "*?["); > + if (pat[len]) return GLOB_NOMATCH; > } else > return GLOB_NOMATCH; > + tail = &head; > + if (append(&tail, pat, len, 0)) > + return GLOB_NOSPACE; > + cnt++; > } > > if (flags & GLOB_APPEND) { The documentation for this flag is really poor. Do you know how it's supposed to interact with escaped characters? Is it really supposed to refuse to expand to the literal pattern when the literal pattern contains an escaped *, ?, or [ but not a special one? Otherwise I think this looks ok. Nice use of strcspn. Rich