aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Pinto <danielpinto52@gmail.com>2020-10-03 04:10:52 +0100
committerDaniel Pinto <danielpinto52@gmail.com>2020-10-03 04:10:52 +0100
commit304ae473cac9e15d5a893d3d95e0479649758bbd (patch)
treeb3a013d6af6f75439305a3e44f697d3f923b37a6 /src
parentf2968c3aac07425a6b4c188aa770b208f8e962b8 (diff)
downloadtor-304ae473cac9e15d5a893d3d95e0479649758bbd.tar.gz
tor-304ae473cac9e15d5a893d3d95e0479649758bbd.zip
Fix %include bug with pattern with */ on glibc < 2.19 #40141
Fix bug where %including a pattern ending in */ would include files and folders (instead of folders only) in versions of glibc < 2.19.
Diffstat (limited to 'src')
-rw-r--r--src/lib/fs/path.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lib/fs/path.c b/src/lib/fs/path.c
index 1a15969419..2eef4bded7 100644
--- a/src/lib/fs/path.c
+++ b/src/lib/fs/path.c
@@ -598,6 +598,12 @@ tor_glob(const char *pattern)
return NULL;
}
+ // #40141: workaround for bug in glibc < 2.19 where patterns ending in path
+ // separator match files and folders instead of folders only
+ size_t pattern_len = strlen(pattern);
+ bool dir_only = has_glob(pattern) &&
+ pattern_len > 0 && pattern[pattern_len-1] == *PATH_SEPARATOR;
+
result = smartlist_new();
size_t i;
for (i = 0; i < matches.gl_pathc; i++) {
@@ -606,7 +612,12 @@ tor_glob(const char *pattern)
if (len > 0 && match[len-1] == *PATH_SEPARATOR) {
match[len-1] = '\0';
}
- smartlist_add(result, match);
+
+ if (!dir_only || (dir_only && is_dir(file_status(match)))) {
+ smartlist_add(result, match);
+ } else {
+ tor_free(match);
+ }
}
globfree(&matches);
#else