wrong working directory in symlinked files
| Bug #50159 | wrong working directory in symlinked files | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2009-11-12 15:39 UTC | Modified: | 2009-11-30 14:26 UTC |
|
||||||||||
| From: | cweiske@php.net | Assigned: | dmitry (profile) | |||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 5.3.1RC3 | OS: | * | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2009-11-12 15:39 UTC] cweiske@php.net
Description: ------------ getcwd() and the current working directory does not work correctly anymore on php 5.3.0 and 5.3.1RCx when executing a symlinked file. In php versions before 5.3.0, the current working directory of a file was the directory below the document root of the web server. in 5.3.0, it's the target directory of the symlinked file. Imagine the following file layout: /var/www/host/ - webserver document root /var/www/host/config.php /var/www/host/index.php - symlink to /usr/share/app/index.php When opening index.php, getcwd() returns /usr/share/app/ in 5.3.0 and 5.3.1rc(1|2|3), while it returned /var/www/host/ on 5.2.x. This change causes real problems because now it is impossible to share application code easily among installations!
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-11-12 16:24 UTC] pajoye@php.net
[2009-11-12 22:24 UTC] cweiske@php.net
[2009-11-13 08:36 UTC] jani@php.net
[2009-11-18 09:46 UTC] srinatar@php.net
hi, in my quick investigation, i think the issue is we are doing chdir to the absolute path of given uri (which is a change in behavior compared to 5.2). here is a rough draft like patch that seems to alleviate this problem. [sriramn@tim-vm2]'PHP_5_3'>svn diff main/fopen_wrappers.c Index: main/fopen_wrappers.c =================================================================== --- main/fopen_wrappers.c (revision 290898) +++ main/fopen_wrappers.c (working copy) @@ -386,7 +386,7 @@ #ifndef PHP_WIN32 struct stat st; #endif - char *path_info, *filename; + char *path_info, *filename, *orig_filename; int length; filename = SG(request_info).path_translated; @@ -455,6 +455,7 @@ } /* if doc_root && path_info */ if (filename) { + orig_filename = estrdup(filename); filename = zend_resolve_path(filename, strlen(filename) TSRMLS_CC); } @@ -488,8 +489,15 @@ STR_FREE(SG(request_info).path_translated); /* for same reason as above */ SG(request_info).path_translated = filename; - file_handle->filename = SG(request_info).path_translated; - file_handle->free_filename = 0; + if (orig_filename) { + file_handle->filename = orig_filename; + file_handle->free_filename = 1; + } + else { + file_handle->filename = SG(request_info).path_translated; + file_handle->free_filename = 0; + } + file_handle->handle.fp = fp; file_handle->type = ZEND_HANDLE_FP; applying this patch , seems to work. af course, more thought need to go on this before this can be committed.[2009-11-22 17:58 UTC] cweiske@php.net
[2009-11-30 14:21 UTC] dmitry@php.net