aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2020-09-09 22:08:54 +0000
committerDavid Goulet <dgoulet@torproject.org>2020-09-10 10:51:57 -0400
commit1c4b140427aeb36d80475e92fe57154fcc8abcf3 (patch)
tree068b66118c83ee5503bac61d6a34c78edd57bb61
parent12c758312651c09eb68e9f4e04a7fd3ad9c3a811 (diff)
downloadtor-1c4b140427aeb36d80475e92fe57154fcc8abcf3.tar.gz
tor-1c4b140427aeb36d80475e92fe57154fcc8abcf3.zip
Check if glob() is available at build-time.
This patch disables the glob() support in the path library if glob() is unavailable at build-time. This currently happens with the Android NDK used for Tor Browser. See: https://bugs.torproject.org/tpo/core/tor/40114
-rw-r--r--configure.ac2
-rw-r--r--src/lib/fs/path.c15
-rw-r--r--src/test/test_util.c12
3 files changed, 24 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 2e1de76606..74f2379fca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -845,6 +845,8 @@ fi
AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
+AC_CHECK_FUNCS(glob)
+
AC_MSG_CHECKING([whether free(NULL) works])
AC_RUN_IFELSE([AC_LANG_PROGRAM([
#include <stdlib.h>
diff --git a/src/lib/fs/path.c b/src/lib/fs/path.c
index f03cecf52d..1a15969419 100644
--- a/src/lib/fs/path.c
+++ b/src/lib/fs/path.c
@@ -532,7 +532,7 @@ unglob_win32(const char *pattern, int prev_sep, int next_sep)
tor_free(path_until_glob);
return result;
}
-#else /* !defined(_WIN32) */
+#elif HAVE_GLOB
/** Same as opendir but calls sandbox_intern_string before */
static DIR *
prot_opendir(const char *name)
@@ -559,7 +559,7 @@ wrap_closedir(void *arg)
{
closedir(arg);
}
-#endif /* defined(_WIN32) */
+#endif /* defined(HAVE_GLOB) */
/** Return a new list containing the paths that match the pattern
* <b>pattern</b>. Return NULL on error. On POSIX systems, errno is set by the
@@ -568,14 +568,15 @@ wrap_closedir(void *arg)
struct smartlist_t *
tor_glob(const char *pattern)
{
- smartlist_t *result;
+ smartlist_t *result = NULL;
+
#ifdef _WIN32
// PathMatchSpec does not support forward slashes, change them to backslashes
char *pattern_normalized = tor_strdup(pattern);
tor_strreplacechar(pattern_normalized, '/', *PATH_SEPARATOR);
result = get_glob_paths(pattern_normalized, unglob_win32, true);
tor_free(pattern_normalized);
-#else /* !(defined(_WIN32)) */
+#elif HAVE_GLOB /* !(defined(_WIN32)) */
glob_t matches;
int flags = GLOB_ERR | GLOB_NOSORT;
#ifdef GLOB_ALTDIRFUNC
@@ -608,7 +609,11 @@ tor_glob(const char *pattern)
smartlist_add(result, match);
}
globfree(&matches);
-#endif /* defined(_WIN32) */
+#else
+ (void)pattern;
+ return result;
+#endif /* !defined(HAVE_GLOB) */
+
return result;
}
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 0e2550d5c5..3ce7103ade 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4440,6 +4440,7 @@ test_util_glob(void *ptr)
{
(void)ptr;
+#ifdef HAVE_GLOB
smartlist_t *results = NULL;
int r, i;
char *dir1 = NULL, *dir2 = NULL, *forbidden = NULL, *dirname = NULL;
@@ -4656,6 +4657,11 @@ test_util_glob(void *ptr)
SMARTLIST_FOREACH(results, char *, f, tor_free(f));
smartlist_free(results);
}
+#else
+ tt_skip();
+ done:
+ return;
+#endif
}
static void
@@ -4663,6 +4669,7 @@ test_util_get_glob_opened_files(void *ptr)
{
(void)ptr;
+#ifdef HAVE_GLOB
smartlist_t *results = NULL;
int r, i;
char *dir1 = NULL, *dir2 = NULL, *forbidden = NULL, *dirname = NULL;
@@ -4843,6 +4850,11 @@ test_util_get_glob_opened_files(void *ptr)
SMARTLIST_FOREACH(results, char *, f, tor_free(f));
smartlist_free(results);
}
+#else
+ tt_skip();
+ done:
+ return;
+#endif
}
static void