diff options
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/TSRM.c | 2 | ||||
-rw-r--r-- | TSRM/TSRM.h | 2 | ||||
-rw-r--r-- | TSRM/tsrm_nw.c | 4 | ||||
-rw-r--r-- | TSRM/tsrm_nw.h | 2 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.c | 65 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.h | 7 | ||||
-rw-r--r-- | TSRM/tsrm_win32.c | 18 | ||||
-rw-r--r-- | TSRM/tsrm_win32.h | 4 |
8 files changed, 79 insertions, 25 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c index 625bd5d85..368178ed0 100644 --- a/TSRM/TSRM.c +++ b/TSRM/TSRM.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Thread Safe Resource Manager | +----------------------------------------------------------------------+ - | Copyright (c) 1999-2009, Andi Gutmans, Sascha Schumann, Zeev Suraski | + | Copyright (c) 1999-2010, Andi Gutmans, Sascha Schumann, Zeev Suraski | | This source file is subject to the TSRM license, that is bundled | | with this package in the file LICENSE | +----------------------------------------------------------------------+ diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h index 5343779d9..cd6618f91 100644 --- a/TSRM/TSRM.h +++ b/TSRM/TSRM.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Thread Safe Resource Manager | +----------------------------------------------------------------------+ - | Copyright (c) 1999-2009, Andi Gutmans, Sascha Schumann, Zeev Suraski | + | Copyright (c) 1999-2010, Andi Gutmans, Sascha Schumann, Zeev Suraski | | This source file is subject to the TSRM license, that is bundled | | with this package in the file LICENSE | +----------------------------------------------------------------------+ diff --git a/TSRM/tsrm_nw.c b/TSRM/tsrm_nw.c index 4a9ccabdd..ac566a411 100644 --- a/TSRM/tsrm_nw.c +++ b/TSRM/tsrm_nw.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_nw.c 272370 2008-12-31 11:15:49Z sebastian $ */ +/* $Id: tsrm_nw.c 293036 2010-01-03 09:23:27Z sebastian $ */ #include <stdlib.h> #include <stdio.h> diff --git a/TSRM/tsrm_nw.h b/TSRM/tsrm_nw.h index e2fe4f539..489505954 100644 --- a/TSRM/tsrm_nw.h +++ b/TSRM/tsrm_nw.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 37b9820ea..251fd2f8d 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.c 289780 2009-10-19 23:38:55Z pajoye $ */ +/* $Id: tsrm_virtual_cwd.c 294520 2010-02-04 09:57:30Z pajoye $ */ #include <sys/types.h> #include <sys/stat.h> @@ -432,8 +432,8 @@ CWD_API char *virtual_getcwd(char *buf, size_t size TSRMLS_DC) /* {{{ */ static inline unsigned long realpath_cache_key(const char *path, int path_len TSRMLS_DC) /* {{{ */ { register unsigned long h; - char *bucket_key = tsrm_win32_get_path_sid_key(path TSRMLS_CC); - char *bucket_key_start = (char *)bucket_key; + char *bucket_key_start = tsrm_win32_get_path_sid_key(path TSRMLS_CC); + char *bucket_key = (char *)bucket_key_start; const char *e = bucket_key + strlen(bucket_key); if (!bucket_key) { @@ -444,11 +444,7 @@ static inline unsigned long realpath_cache_key(const char *path, int path_len TS h *= 16777619; h ^= *bucket_key++; } - /* if no SID were present the path is returned. Otherwise a Heap - allocated string is returned. */ - if (bucket_key_start != path) { - LocalFree(bucket_key_start); - } + HeapFree(GetProcessHeap(), 0, (LPVOID)bucket_key_start); return h; } /* }}} */ @@ -590,6 +586,22 @@ CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_ } /* }}} */ +CWD_API int realpath_cache_size(TSRMLS_D) +{ + return CWDG(realpath_cache_size); +} + +CWD_API int realpath_cache_max_buckets(TSRMLS_D) +{ + return (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0])); +} + +CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D) +{ + return CWDG(realpath_cache); +} + + #undef LINK_MAX #define LINK_MAX 32 @@ -702,7 +714,9 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i tmp = tsrm_do_alloca(len+1, use_heap); memcpy(tmp, path, len+1); - if(save && (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { + if(save && + !(IS_UNC_PATH(path, len) && len >= 3 && path[2] != '?') && + (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { /* File is a reparse point. Get the target */ HANDLE hLink = NULL; REPARSE_DATA_BUFFER * pbuffer; @@ -983,9 +997,19 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func time_t t; int ret; int add_slash; + void *tmp; TSRMLS_FETCH(); if (path_length == 0 || path_length >= MAXPATHLEN-1) { +#ifdef TSRM_WIN32 +# if _MSC_VER < 1300 + errno = EINVAL; +# else + _set_errno(EINVAL); +# endif +#else + errno = EINVAL; +#endif return 1; } @@ -1127,7 +1151,16 @@ verify: CWD_STATE_COPY(&old_state, state); state->cwd_length = path_length; - state->cwd = (char *) realloc(state->cwd, state->cwd_length+1); + + tmp = realloc(state->cwd, state->cwd_length+1); + if (tmp == NULL) { +#if VIRTUAL_CWD_DEBUG + fprintf (stderr, "Out of memory\n"); +#endif + return 1; + } + state->cwd = (char *) tmp; + memcpy(state->cwd, resolved_path, state->cwd_length+1); if (verify_path(state)) { CWD_STATE_FREE(state); @@ -1139,7 +1172,15 @@ verify: } } else { state->cwd_length = path_length; - state->cwd = (char *) realloc(state->cwd, state->cwd_length+1); + tmp = realloc(state->cwd, state->cwd_length+1); + if (tmp == NULL) { +#if VIRTUAL_CWD_DEBUG + fprintf (stderr, "Out of memory\n"); +#endif + return 1; + } + state->cwd = (char *) tmp; + memcpy(state->cwd, resolved_path, state->cwd_length+1); ret = 0; } diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h index 7f612bfec..c18bc0f4b 100644 --- a/TSRM/tsrm_virtual_cwd.h +++ b/TSRM/tsrm_virtual_cwd.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.h 287673 2009-08-25 09:16:53Z pajoye $ */ +/* $Id: tsrm_virtual_cwd.h 293036 2010-01-03 09:23:27Z sebastian $ */ #ifndef VIRTUAL_CWD_H #define VIRTUAL_CWD_H @@ -238,6 +238,9 @@ extern virtual_cwd_globals cwd_globals; CWD_API void realpath_cache_clean(TSRMLS_D); CWD_API void realpath_cache_del(const char *path, int path_len TSRMLS_DC); CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_len, time_t t TSRMLS_DC); +CWD_API int realpath_cache_size(TSRMLS_D); +CWD_API int realpath_cache_max_buckets(TSRMLS_D); +CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D); /* The actual macros to be used in programs using TSRM * If the program defines VIRTUAL_DIR it will use the diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index b224d4b10..2267488a9 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_win32.c 290166 2009-11-03 10:48:12Z pajoye $ */ +/* $Id: tsrm_win32.c 294728 2010-02-07 21:09:19Z pajoye $ */ #include <stdio.h> #include <fcntl.h> @@ -176,6 +176,7 @@ PSID tsrm_win32_get_token_sid(HANDLE hToken) if (!CopySid(sid_len, pResultSid, pTokenUser->User.Sid)) { goto Finished; } + HeapFree(GetProcessHeap(), 0, (LPVOID)pTokenUser); return pResultSid; Finished: @@ -222,11 +223,13 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode) } if(access(pathname, mode)) { + free(real_path); return errno; } /* If only existence check is made, return now */ if (mode == 0) { + free(real_path); return 0; } @@ -271,6 +274,9 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode) if (!DuplicateToken(thread_token, SecurityImpersonation, &TWG(impersonation_token))) { goto Finished; } + } else { + /* we already have it, free it then */ + free(token_sid); } if (CWDG(realpath_cache_size_limit)) { @@ -299,7 +305,7 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode) fAccess = bucket->is_writable; goto Finished; } - desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE; + desired_access = FILE_GENERIC_WRITE; } else if(mode <= 4) { if(bucket != NULL && bucket->is_rvalid) { fAccess = bucket->is_readable; @@ -344,6 +350,11 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode) else if(desired_access == FILE_GENERIC_WRITE) { bucket->is_wvalid = 1; bucket->is_writable = fAccess; + } else if (desired_access == (FILE_GENERIC_READ | FILE_GENERIC_WRITE)) { + bucket->is_rvalid = 1; + bucket->is_readable = fAccess; + bucket->is_wvalid = 1; + bucket->is_writable = fAccess; } } @@ -518,7 +529,6 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, if (err == ERROR_NO_TOKEN) { asuser = FALSE; } - } cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2); diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h index 7cd966918..0d6f2ab7c 100644 --- a/TSRM/tsrm_win32.h +++ b/TSRM/tsrm_win32.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2010 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_win32.h 289780 2009-10-19 23:38:55Z pajoye $ */ +/* $Id: tsrm_win32.h 293036 2010-01-03 09:23:27Z sebastian $ */ #ifndef TSRM_WIN32_H #define TSRM_WIN32_H |