]> granicus.if.org Git - php/commitdiff
Fix for bug 41822. expand_filepath() will now return a relative path under the speci...
authorRobert Thompson <ab5602@php.net>
Tue, 9 Oct 2007 02:41:14 +0000 (02:41 +0000)
committerRobert Thompson <ab5602@php.net>
Tue, 9 Oct 2007 02:41:14 +0000 (02:41 +0000)
main/fopen_wrappers.c

index bcff191d77d97c1126774cdf761171e6b064d18e..ded6a5405206bc10e42c60a9ecfe870476fdd7bb 100644 (file)
@@ -577,18 +577,30 @@ PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC)
 {
        cwd_state new_state;
        char cwd[MAXPATHLEN];
-       char *result;
 
-       if (!filepath[0]) {
-               return NULL;
-       } else if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) {
-               cwd[0] = '\0';
-       } else{
-               result = VCWD_GETCWD(cwd, MAXPATHLEN);
-               if (!result) {
-                       cwd[0] = '\0';
-               }
-       }
+        if (!filepath[0]) {
+                return NULL;
+        } else if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) {
+                cwd[0] = '\0';
+        } else {
+                const char *iam = SG(request_info).path_translated;
+                char *result = VCWD_GETCWD(cwd, MAXPATHLEN);
+                if (!result && (iam != filepath)) {
+                        int fdtest = -1;
+                        fdtest = VCWD_OPEN(filepath, O_RDONLY);
+                        if (fdtest != -1) {
+                                /* return a relative file path if for any reason 
+                                   we cannot cannot getcwd() and the requested, 
+                                   relatively referenced file is accessible */
+                                int copy_len = strlen(filepath)>MAXPATHLEN-1?MAXPATHLEN-1:strlen(filepath);
+                                real_path = estrndup(filepath, copy_len);
+                                return real_path;
+                            }   
+                         }
+                else {
+                        cwd[0] = '\0';
+                        }
+                }
 
        new_state.cwd = strdup(cwd);
        new_state.cwd_length = strlen(cwd);