From 2e76b024015cb1f0263bfe53746a759b7d255a20 Mon Sep 17 00:00:00 2001 From: Hello71 Date: Sat, 9 Jan 2021 19:16:20 +0000 Subject: path: fix directory special case --- changes/glob_dir | 3 +++ src/lib/fs/path.c | 10 ++++++---- src/test/test_util.c | 7 ------- 3 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 changes/glob_dir diff --git a/changes/glob_dir b/changes/glob_dir new file mode 100644 index 0000000000..cb9907f7e4 --- /dev/null +++ b/changes/glob_dir @@ -0,0 +1,3 @@ + o Minor bugfixes (config): + - Fix globbing directories on all platforms. Fixes compilation on musl. + Fixes bug 40141; bugfix on 0.4.5.1-alpha. diff --git a/src/lib/fs/path.c b/src/lib/fs/path.c index c2fdddb9db..39794cb84e 100644 --- a/src/lib/fs/path.c +++ b/src/lib/fs/path.c @@ -611,11 +611,13 @@ 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 + // #40141, !249: workaround for glibc bug where patterns ending in path + // separator match files and folders instead of folders only. + // this could be in #ifdef __GLIBC__ but: 1. it might affect other libcs too, + // and 2. it doesn't cost much to stat each match again since libc is already + // supposed to do it (otherwise the file may be on slow NFS or something) size_t pattern_len = strlen(pattern); - bool dir_only = has_glob(pattern) && - pattern_len > 0 && pattern[pattern_len-1] == *PATH_SEPARATOR; + bool dir_only = pattern_len > 0 && pattern[pattern_len-1] == *PATH_SEPARATOR; result = smartlist_new(); size_t i; diff --git a/src/test/test_util.c b/src/test/test_util.c index b3a1e2caca..546b3c2907 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4562,15 +4562,8 @@ test_util_glob(void *ptr) TEST("file1"); EXPECT(results_test9); -#if defined(__APPLE__) || defined(__darwin__) || \ - defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD) TEST("file1"PATH_SEPARATOR); EXPECT_EMPTY(); -#else - const char *results_test10[] = {"file1"}; - TEST("file1"PATH_SEPARATOR); - EXPECT(results_test10); -#endif // test path separator at end - with wildcards and linux path separator const char *results_test11[] = {"dir1", "dir2", "forbidden"}; -- cgit v1.2.3-54-g00ecf From d2c2204b2ac564cd71fd0be1ea3efabd6f84fc36 Mon Sep 17 00:00:00 2001 From: Alexander Færøy Date: Fri, 22 Jan 2021 13:22:14 +0000 Subject: Slightly reword the changes file and rename it. --- changes/bug40141 | 4 ++++ changes/glob_dir | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changes/bug40141 delete mode 100644 changes/glob_dir diff --git a/changes/bug40141 b/changes/bug40141 new file mode 100644 index 0000000000..cf2641cfde --- /dev/null +++ b/changes/bug40141 @@ -0,0 +1,4 @@ + o Minor bugfixes (configuration): + - Fix globbing directories on all platforms when using %include options in + configuration files. This patch also fixes compilation on musl libc based + systems. Fixes bug 40141; bugfix on 0.4.5.1-alpha. diff --git a/changes/glob_dir b/changes/glob_dir deleted file mode 100644 index cb9907f7e4..0000000000 --- a/changes/glob_dir +++ /dev/null @@ -1,3 +0,0 @@ - o Minor bugfixes (config): - - Fix globbing directories on all platforms. Fixes compilation on musl. - Fixes bug 40141; bugfix on 0.4.5.1-alpha. -- cgit v1.2.3-54-g00ecf