From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11363 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] glob: fix / matching Date: Sat, 27 May 2017 22:55:20 -0400 Message-ID: <20170528025520.GF1627@brightrain.aerifal.cx> References: <20170528015918.GC1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1495940135 1798 195.159.176.226 (28 May 2017 02:55:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 28 May 2017 02:55:35 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11378-gllmg-musl=m.gmane.org@lists.openwall.com Sun May 28 04:55:29 2017 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.84_2) (envelope-from ) id 1dEoMa-0000IU-QV for gllmg-musl@m.gmane.org; Sun, 28 May 2017 04:55:28 +0200 Original-Received: (qmail 17504 invoked by uid 550); 28 May 2017 02:55:32 -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 17485 invoked from network); 28 May 2017 02:55:32 -0000 Content-Disposition: inline In-Reply-To: <20170528015918.GC1627@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11363 Archived-At: On Sat, May 27, 2017 at 09:59:18PM -0400, Rich Felker wrote: > On Fri, May 19, 2017 at 04:59:13PM +0200, Julien Ramseier wrote: > > glob(3) currently fails matching "/", due to any '/' being > > removed from the start of the pattern before checking if > > it's empty. > > > > > diff --git a/src/regex/glob.c b/src/regex/glob.c > > index 5b6ff12..53f3a4e 100644 > > --- a/src/regex/glob.c > > +++ b/src/regex/glob.c > > @@ -156,18 +156,11 @@ static int sort(const void *a, const void *b) > > > > int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *restrict g) > > { > > - const char *p=pat, *d; > > + const char *p = pat; > > struct match head = { .next = NULL }, *tail = &head; > > size_t cnt, i; > > size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; > > int error = 0; > > - > > - if (*p == '/') { > > - for (; *p == '/'; p++); > > - d = "/"; > > - } else { > > - d = ""; > > - } > > > > if (!errfunc) errfunc = ignore_err; > > > > @@ -179,12 +172,19 @@ int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, i > > > > if (strnlen(p, PATH_MAX+1) > PATH_MAX) return GLOB_NOSPACE; > > > > - if (*p) error = match_in_dir(d, p, flags, errfunc, &tail); > > + if (*p) { > > + const char *d = ""; > > + if (*p == '/') { > > + for (; *p == '/'; p++); > > + d = "/"; > > + } > > + error = match_in_dir(d, p, flags, errfunc, &tail); > > + } > > I'm confused how this patch differs from just removing the "if (*p)" > condition before calling match_in_dir. Does match_in_dir actually work > if p points to an empty string? I thought not... Hmm, just removing the "if (*p)" seems to make it work; it looks like match_in_dir covers this case fine. I'd like a second opinion on whether this looks okay since I haven't touched this code in years, but I suspect it'll turn out to be an okay fix for now... > > Also, any feedback concerning > > http://www.openwall.com/lists/musl/2017/01/12/5 ? > > I'll have to actually trace through what it does to figure out why > that's happening; the intent was that it work for all components, I > think.. > > Really the whole glob() implementation could use a complete rewrite. ...but I still think the code is due for a rewrite. Just the fact that it collapses all ///// to / is rather bad. Rich