summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Le Blanc <lbarnaud@php.net>2008-08-11 15:33:02 +0000
committerArnaud Le Blanc <lbarnaud@php.net>2008-08-11 15:33:02 +0000
commitc573dd661421c6bb3413f79ebecb66ca93d84e3c (patch)
treefd36bc60cfba458f103cf6231a30644dcb6768ea
parentde24949cce44c870139d35833c51b50a73e71231 (diff)
downloadphp-git-c573dd661421c6bb3413f79ebecb66ca93d84e3c.tar.gz
MFH: Missing files in previous commit (Check the relevant path for open_basedir
in symlink())
-rw-r--r--main/fopen_wrappers.c19
-rw-r--r--main/fopen_wrappers.h1
2 files changed, 19 insertions, 1 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index fafe32315e..feabfb85cc 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -723,6 +723,14 @@ PHPAPI char *php_strip_url_passwd(char *url)
*/
PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC)
{
+ return expand_filepath_ex(filepath, real_path, NULL, 0 TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ expand_filepath_ex
+ */
+PHPAPI char *expand_filepath_ex(const char *filepath, char *real_path, const char *relative_to, size_t relative_to_len TSRMLS_DC)
+{
cwd_state new_state;
char cwd[MAXPATHLEN];
int copy_len;
@@ -733,7 +741,16 @@ PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC)
cwd[0] = '\0';
} else {
const char *iam = SG(request_info).path_translated;
- char *result = VCWD_GETCWD(cwd, MAXPATHLEN);
+ const char *result;
+ if (relative_to) {
+ if (relative_to_len > MAXPATHLEN-1U) {
+ return NULL;
+ }
+ result = relative_to;
+ memcpy(cwd, relative_to, relative_to_len+1U);
+ } else {
+ result = VCWD_GETCWD(cwd, MAXPATHLEN);
+ }
if (!result && (iam != filepath)) {
int fdtest = -1;
diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h
index 2afd24183b..1b8113c10c 100644
--- a/main/fopen_wrappers.h
+++ b/main/fopen_wrappers.h
@@ -26,6 +26,7 @@ BEGIN_EXTERN_C()
PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC);
PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC);
+PHPAPI char *expand_filepath_ex(const char *filepath, char *real_path, const char *relative_to, size_t relative_to_len TSRMLS_DC);
PHPAPI int php_check_open_basedir(const char *path TSRMLS_DC);
PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC);