"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib/fs/path.c" between
tor-0.4.5.7.tar.gz and tor-0.4.5.8.tar.gz

About: Tor is an anonymous Internet communication system - a network of virtual tunnels that allows people and groups to improve their privacy and security on the Internet.

path.c  (tor-0.4.5.7):path.c  (tor-0.4.5.8)
skipping to change at line 574 skipping to change at line 574
return -1; return -1;
} }
return lstat(sandbox_intern_string(pathname), buf); return lstat(sandbox_intern_string(pathname), buf);
} }
/** As closedir, but has the right type for gl_closedir */ /** As closedir, but has the right type for gl_closedir */
static void static void
wrap_closedir(void *arg) wrap_closedir(void *arg)
{ {
closedir(arg); closedir(arg);
} }
/** 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) */ #endif /* defined(HAVE_GLOB) */
/** Return a new list containing the paths that match the pattern /** 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 * <b>pattern</b>. Return NULL on error. On POSIX systems, errno is set by the
* glob function or is set to EPERM if glob tried to access a file not allowed * glob function or is set to EPERM if glob tried to access a file not allowed
* by the seccomp sandbox. * by the seccomp sandbox.
*/ */
struct smartlist_t * struct smartlist_t *
tor_glob(const char *pattern) tor_glob(const char *pattern)
{ {
smartlist_t *result = NULL; smartlist_t *result = NULL;
#ifdef _WIN32 #ifdef _WIN32
// PathMatchSpec does not support forward slashes, change them to backslashes // PathMatchSpec does not support forward slashes, change them to backslashes
char *pattern_normalized = tor_strdup(pattern); char *pattern_normalized = tor_strdup(pattern);
tor_strreplacechar(pattern_normalized, '/', *PATH_SEPARATOR); tor_strreplacechar(pattern_normalized, '/', *PATH_SEPARATOR);
result = get_glob_paths(pattern_normalized, unglob_win32, true); result = get_glob_paths(pattern_normalized, unglob_win32, true);
tor_free(pattern_normalized); tor_free(pattern_normalized);
#elif HAVE_GLOB /* !(defined(_WIN32)) */ #elif HAVE_GLOB /* !(defined(_WIN32)) */
glob_t matches; glob_t matches;
int flags = GLOB_ERR | GLOB_NOSORT; int flags = GLOB_NOSORT;
#ifdef GLOB_ALTDIRFUNC #ifdef GLOB_ALTDIRFUNC
/* use functions that call sandbox_intern_string */ /* use functions that call sandbox_intern_string */
flags |= GLOB_ALTDIRFUNC; flags |= GLOB_ALTDIRFUNC;
typedef void *(*gl_opendir)(const char * name); typedef void *(*gl_opendir)(const char * name);
typedef struct dirent *(*gl_readdir)(void *); typedef struct dirent *(*gl_readdir)(void *);
typedef void (*gl_closedir)(void *); typedef void (*gl_closedir)(void *);
matches.gl_opendir = (gl_opendir) &prot_opendir; matches.gl_opendir = (gl_opendir) &prot_opendir;
matches.gl_readdir = (gl_readdir) &readdir; matches.gl_readdir = (gl_readdir) &readdir;
matches.gl_closedir = (gl_closedir) &wrap_closedir; matches.gl_closedir = (gl_closedir) &wrap_closedir;
matches.gl_stat = &prot_stat; matches.gl_stat = &prot_stat;
matches.gl_lstat = &prot_lstat; matches.gl_lstat = &prot_lstat;
#endif /* defined(GLOB_ALTDIRFUNC) */ #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) { if (ret == GLOB_NOMATCH) {
return smartlist_new(); return smartlist_new();
} else if (ret != 0) { } else if (ret != 0) {
return NULL; return NULL;
} }
// #40141: workaround for bug in glibc < 2.19 where patterns ending in path // #40141: workaround for bug in glibc < 2.19 where patterns ending in path
// separator match files and folders instead of folders only // separator match files and folders instead of folders only
size_t pattern_len = strlen(pattern); size_t pattern_len = strlen(pattern);
bool dir_only = has_glob(pattern) && bool dir_only = has_glob(pattern) &&
 End of changes. 3 change blocks. 
2 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)