aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-12 18:17:02 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-12 20:02:43 +0900
commit7dc0511ea4be210f82abb1c82a31aec3a4fe5736 (patch)
tree641de37d2e24fe9c7ba3d30536a7c9b0886537e5 /dir.c
parentccabf4966f4c5a7e19fec52b690d07bf471fc5d1 (diff)
downloadruby-7dc0511ea4be210f82abb1c82a31aec3a4fe5736.tar.gz
Remove "." and ".." from Dir.glob with FNM_DOTMATCH [Bug #17280]
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index bedbdd9f83..48c9eaefa0 100644
--- a/dir.c
+++ b/dir.c
@@ -222,6 +222,7 @@ typedef enum {
#define FNM_SHORTNAME 0
#endif
#define FNM_GLOB_NOSORT 0x40
+#define FNM_GLOB_SKIPDOT 0x80
#define FNM_NOMATCH 1
#define FNM_ERROR 2
@@ -2413,6 +2414,10 @@ glob_helper(
}
return status;
}
+
+ int skipdot = (flags & FNM_GLOB_SKIPDOT);
+ flags |= FNM_GLOB_SKIPDOT;
+
while ((dp = glob_getent(&globent, flags, enc)) != NULL) {
char *buf;
rb_pathtype_t new_pathtype = path_unknown;
@@ -2423,11 +2428,12 @@ glob_helper(
name = dp->d_name;
namlen = dp->d_namlen;
- if (recursive && name[0] == '.') {
+ if (name[0] == '.') {
++dotfile;
if (namlen == 1) {
/* unless DOTMATCH, skip current directories not to recurse infinitely */
- if (!(flags & FNM_DOTMATCH)) continue;
+ if (recursive && !(flags & FNM_DOTMATCH)) continue;
+ if (skipdot) continue;
++dotfile;
new_pathtype = path_directory; /* force to skip stat/lstat */
}