diff options
| -rw-r--r-- | main/SAPI.c | 2 | ||||
| -rw-r--r-- | main/fopen_wrappers.c | 2 | ||||
| -rw-r--r-- | main/php.h | 2 | ||||
| -rw-r--r-- | main/php_realpath.c | 2 | ||||
| -rw-r--r-- | main/php_virtual_cwd.c | 16 | ||||
| -rw-r--r-- | main/php_virtual_cwd.h | 9 | ||||
| -rw-r--r-- | main/safe_mode.c | 6 |
7 files changed, 33 insertions, 6 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index 3f29c97769..e2f58790ff 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -534,7 +534,7 @@ SAPI_API struct stat *sapi_get_stat() if (sapi_module.get_stat) { return sapi_module.get_stat(SLS_C); } else { - if (!SG(request_info).path_translated || (stat(SG(request_info).path_translated, &SG(global_stat))==-1)) { + if (!SG(request_info).path_translated || (V_STAT(SG(request_info).path_translated, &SG(global_stat))==-1)) { return NULL; } return &SG(global_stat); diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index bce69d9728..a3473be227 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -408,7 +408,7 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** } snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename); if (PG(safe_mode)) { - if (stat(trypath, &sb) == 0 && (!php_checkuid(trypath, cm))) { + if (V_STAT(trypath, &sb) == 0 && (!php_checkuid(trypath, cm))) { efree(pathbuf); return NULL; } diff --git a/main/php.h b/main/php.h index 89968361f1..db23919e21 100644 --- a/main/php.h +++ b/main/php.h @@ -294,12 +294,14 @@ PHPAPI int cfg_get_string(char *varname, char **result); #define V_CHDIR(path) virtual_chdir(path) #define V_CHDIR_FILE(path) virtual_chdir_file(path) #define V_GETWD(buf) +#define V_STAT(path, buff) virtual_stat(path, buff) #else #define V_GETCWD(buff, size) getcwd(buff,size) #define V_FOPEN(path, mode) fopen(path, mode) #define V_CHDIR(path) chdir(path) #define V_CHDIR_FILE(path) chdir_file(path) #define V_GETWD(buf) getwd(buf) +#define V_STAT(path, buff) stat(path, buff) #endif #include "zend_constants.h" diff --git a/main/php_realpath.c b/main/php_realpath.c index d60efa362c..66dfe5e9ca 100644 --- a/main/php_realpath.c +++ b/main/php_realpath.c @@ -251,7 +251,7 @@ char *php_realpath(char *path, char resolved_path []) { } /* Check if the resolved path is a directory */ - if (stat(path_construction, &filestat) != 0) return NULL; + if (V_STAT(path_construction, &filestat) != 0) return NULL; if (S_ISDIR(filestat.st_mode)) { /* It's a directory, append a / if needed */ if (*(writepos-1) != '/') { diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index e773fde9ee..3613cc77f8 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <ctype.h> + #include "php_virtual_cwd.h" #ifdef ZTS @@ -366,6 +367,21 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode) return f; } +CWD_API int virtual_stat(const char *path, struct stat *buf) +{ + cwd_state new_state; + int retval; + CWDLS_FETCH(); + + CWD_STATE_COPY(&new_state, &CWDG(cwd)); + + virtual_file_ex(&new_state, path, NULL); + + retval = stat(new_state.cwd, buf); + CWD_STATE_FREE(&new_state); + return retval; +} + #if 0 main(void) diff --git a/main/php_virtual_cwd.h b/main/php_virtual_cwd.h index ab46974d71..a7548c8d59 100644 --- a/main/php_virtual_cwd.h +++ b/main/php_virtual_cwd.h @@ -4,6 +4,14 @@ #include "zend.h" #include "zend_API.h" +#include <sys/types.h> +#include <sys/stat.h> + +#ifndef ZEND_WIN32 +#include <unistd.h> +#endif + + #ifdef PHP_EXPORTS #define CWD_EXPORTS #endif @@ -34,6 +42,7 @@ CWD_API int virtual_chdir(char *path); CWD_API int virtual_chdir_file(char *path); CWD_API int virtual_filepath(char *path, char **filepath); CWD_API FILE *virtual_fopen(const char *path, const char *mode); +CWD_API int virtual_stat(const char *path, struct stat *buf); CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path); ZEND_BEGIN_MODULE_GLOBALS(cwd) diff --git a/main/safe_mode.c b/main/safe_mode.c index ac33ba88db..4f4344291c 100644 --- a/main/safe_mode.c +++ b/main/safe_mode.c @@ -57,7 +57,7 @@ PHPAPI int php_checkuid(const char *fn, int mode) { } if (mode<3) { - ret = stat(fn,&sb); + ret = V_STAT(fn,&sb); if (ret<0 && mode < 2) { php_error(E_WARNING,"Unable to access %s",fn); return(mode); @@ -79,7 +79,7 @@ PHPAPI int php_checkuid(const char *fn, int mode) { if (s) { *s='\0'; - ret = stat(fn,&sb); + ret = V_STAT(fn,&sb); *s='/'; if (ret<0) { php_error(E_WARNING, "Unable to access %s",fn); @@ -92,7 +92,7 @@ PHPAPI int php_checkuid(const char *fn, int mode) { php_error(E_WARNING, "Unable to access current working directory"); return(0); } - ret = stat(s,&sb); + ret = V_STAT(s,&sb); efree(s); if (ret<0) { php_error(E_WARNING, "Unable to access %s",s); |
