]> granicus.if.org Git - php/commitdiff
MFH: Missing files in previous commit (Check the relevant path for open_basedir
authorArnaud Le Blanc <lbarnaud@php.net>
Mon, 11 Aug 2008 15:33:14 +0000 (15:33 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Mon, 11 Aug 2008 15:33:14 +0000 (15:33 +0000)
in symlink())

main/fopen_wrappers.c
main/fopen_wrappers.h

index 736da15b0d0da9e1c2211742ab32edf81dfe1cd8..16c532fb06a62e01e813f3065ec09adc07f7dc82 100644 (file)
@@ -600,6 +600,14 @@ PHPAPI char *php_strip_url_passwd(char *url)
 /* {{{ expand_filepath
  */
 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];
@@ -611,7 +619,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;
index c442d76708ad7a50c471f4e7ae3f728b96213143..3de446e7ca5729c2d23cc1bbf7cab78f4ae02536 100644 (file)
@@ -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);