mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] glob: fix / matching
Date: Sat, 27 May 2017 21:59:18 -0400	[thread overview]
Message-ID: <20170528015918.GC1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <A89BD6D2-A952-40C3-B7EC-B65912A2BB80@gmail.com>

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...

> 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.

Rich


  reply	other threads:[~2017-05-28  1:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-19 14:59 Julien Ramseier
2017-05-28  1:59 ` Rich Felker [this message]
2017-05-28  2:55   ` Rich Felker
2017-05-28 15:06     ` Julien Ramseier
2017-06-01  2:00       ` Rich Felker
2017-06-03 16:15         ` Julien Ramseier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170528015918.GC1627@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).