]> granicus.if.org Git - musl/commitdiff
fix glob descent into . and .. with GLOB_PERIOD
authorRich Felker <dalias@aerifal.cx>
Thu, 7 Sep 2017 01:59:22 +0000 (21:59 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 7 Sep 2017 01:59:22 +0000 (21:59 -0400)
GLOB_PERIOD is a gnu extension, and GNU glob does not seem to honor it
except in the last path component. it's not clear whether this a bug
or intentional, but it seems reasonable that it should exclude the
special entries . and .. when walking.

changes based on report and analysis by Julien Ramseier.

src/regex/glob.c

index 2d4d562e96cede26937638f283d8de934a68293d..6f8425caa35a06623b40f7bd8c48a0a74b0f552d 100644 (file)
@@ -100,6 +100,10 @@ static int match_in_dir(const char *d, const char *p, int flags, int (*errfunc)(
                        continue;
                if (p2 && de->d_type && !S_ISDIR(de->d_type<<12) && !S_ISLNK(de->d_type<<12))
                        continue;
+               if (p2 && de->d_name[0]=='.' && !de->d_name[1])
+                       continue;
+               if (p2 && de->d_name[0]=='.' && de->d_name[1]=='.' && !de->d_name[2])
+                       continue;
                if (*d) {
                        memcpy(name, d, l);
                        name[l] = '/';