Przeglądaj źródła

fix glob descent into . and .. with GLOB_PERIOD

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.
Rich Felker 7 lat temu
rodzic
commit
8c4be3e220
1 zmienionych plików z 4 dodań i 0 usunięć
  1. 4 0
      src/regex/glob.c

+ 4 - 0
src/regex/glob.c

@@ -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] = '/';