summaryrefslogtreecommitdiff
path: root/sapi/cli/php_cli_server.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2011-09-20 07:06:55 +0000
committerXinchen Hui <laruence@php.net>2011-09-20 07:06:55 +0000
commit5dbf73a866586b24e9e566711e6fa866e26992d9 (patch)
treea9e57f93bc9b441ca4b13c164d0e279e8e14b0d5 /sapi/cli/php_cli_server.c
parent6bd693543b58ed1f61e7a3cd81298660770eece8 (diff)
downloadphp-git-5dbf73a866586b24e9e566711e6fa866e26992d9.tar.gz
Fix Bug #55726 (Changing the working directory makes router script inaccessible)
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r--sapi/cli/php_cli_server.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index 26cbeaa0d7..ac669cac4f 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -1877,11 +1877,24 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
}
{
zend_file_handle zfd;
+#if HAVE_BROKEN_GETCWD
+ int old_cwd_fd = -1;
+ old_cwd_fd = open(".", 0);
+#else
+ char *old_cwd;
+ ALLOCA_FLAG(use_heap)
+#define OLD_CWD_SIZE 4096
+ old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
+ old_cwd[0] = '\0';
+ php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
+#endif
+
zfd.type = ZEND_HANDLE_FILENAME;
zfd.filename = server->router;
zfd.handle.fp = NULL;
zfd.free_filename = 0;
zfd.opened_path = NULL;
+
zend_try {
zval *retval = NULL;
if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd)) {
@@ -1893,6 +1906,18 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
decline = 1;
}
} zend_end_try();
+
+#if HAVE_BROKEN_GETCWD
+ if (old_cwd_fd != -1) {
+ fchdir(old_cwd_fd);
+ close(old_cwd_fd);
+ }
+#else
+ if (old_cwd[0] != '\0') {
+ php_ignore_value(VCWD_CHDIR(old_cwd));
+ }
+ free_alloca(old_cwd, use_heap);
+#endif
}
if (decline) {