fix regression in glob with literal . or .. path component

commit 8c4be3e220 was written to
preclude the GLOB_PERIOD extension from matching these directory
entries, but also precluded literal matches.

adjust the check that excludes . and .. to check whether the
GLOB_PERIOD flag is in effect, so that it cannot alter behavior in
cases governed by the standard, and also don't exclude . or .. in any
case where normal glob behavior (fnmatch's FNM_PERIOD flag) would have
included one or both of them (patterns such as ".*").

it's still not clear whether this is the preferred behavior for
GLOB_PERIOD, but at least it's clear that it can no longer break
applications which are not relying on quirks of a nonstandard feature.
This commit is contained in:
Rich Felker 2017-10-21 12:17:49 -04:00
parent 004dc9549b
commit ec04d122f1
1 changed files with 5 additions and 3 deletions

View File

@ -100,9 +100,11 @@ static int match_in_dir(const char *d, const char *p, int flags, int (*errfunc)(
continue; continue;
if (p2 && de->d_type && !S_ISDIR(de->d_type<<12) && !S_ISLNK(de->d_type<<12)) if (p2 && de->d_type && !S_ISDIR(de->d_type<<12) && !S_ISLNK(de->d_type<<12))
continue; continue;
if (p2 && de->d_name[0]=='.' && !de->d_name[1]) /* With GLOB_PERIOD, don't allow matching . or .. unless
continue; * fnmatch would match them with FNM_PERIOD rules in effect. */
if (p2 && de->d_name[0]=='.' && de->d_name[1]=='.' && !de->d_name[2]) if (p2 && (flags & GLOB_PERIOD) && de->d_name[0]=='.'
&& (!de->d_name[1] || de->d_name[1]=='.' && !de->d_name[2])
&& fnmatch(p, de->d_name, fnm_flags | FNM_PERIOD))
continue; continue;
if (*d) { if (*d) {
memcpy(name, d, l); memcpy(name, d, l);