diff options
author | George Kadianakis <desnacked@riseup.net> | 2021-04-08 14:29:08 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2021-04-08 14:29:08 +0300 |
commit | e0b8a79b2e62c69d45cce792f14b127e926082e2 (patch) | |
tree | b8a26646d4ed1f26c16abd6d2b258694968bc425 /src/lib/fs | |
parent | b07ed22cbb43fe0aaac3f1b13f4902cea895d724 (diff) | |
parent | 36768b5756f05774258ca9c5db6379f74dfd6586 (diff) | |
download | tor-e0b8a79b2e62c69d45cce792f14b127e926082e2.tar.gz tor-e0b8a79b2e62c69d45cce792f14b127e926082e2.zip |
Merge branch 'maint-0.4.5'
Diffstat (limited to 'src/lib/fs')
-rw-r--r-- | src/lib/fs/path.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/lib/fs/path.c b/src/lib/fs/path.c index 48d610ab7b..81eb3aa661 100644 --- a/src/lib/fs/path.c +++ b/src/lib/fs/path.c @@ -571,7 +571,20 @@ wrap_closedir(void *arg) { closedir(arg); } -#endif /* defined(_WIN32) || ... */ + +/** Function passed to glob to handle processing errors. <b>epath</b> is the + * path that caused the error and <b>eerrno</b> is the errno set by the + * function that failed. We want to ignore ENOENT and ENOTDIR because, in BSD + * systems, these are not ignored automatically, which makes glob fail when + * globs expand to non-existing paths and GLOB_ERR is set. + */ +static int +glob_errfunc(const char *epath, int eerrno) +{ + (void)epath; + return eerrno == ENOENT || eerrno == ENOTDIR ? 0 : -1; +} +#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 @@ -591,7 +604,7 @@ tor_glob(const char *pattern) tor_free(pattern_normalized); #elif HAVE_GLOB /* !(defined(_WIN32)) */ glob_t matches; - int flags = GLOB_ERR | GLOB_NOSORT; + int flags = GLOB_NOSORT; #ifdef GLOB_ALTDIRFUNC /* use functions that call sandbox_intern_string */ flags |= GLOB_ALTDIRFUNC; @@ -604,7 +617,10 @@ tor_glob(const char *pattern) matches.gl_stat = &prot_stat; matches.gl_lstat = &prot_lstat; #endif /* defined(GLOB_ALTDIRFUNC) */ - int ret = glob(pattern, flags, NULL, &matches); + // use custom error handler to workaround BSD quirks and do not set GLOB_ERR + // because it would make glob fail on error even if the error handler ignores + // the error + int ret = glob(pattern, flags, glob_errfunc, &matches); if (ret == GLOB_NOMATCH) { return smartlist_new(); } else if (ret != 0) { |