summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2012-04-30 12:15:43 +0800
committerXinchen Hui <laruence@php.net>2012-04-30 12:15:43 +0800
commitfd518ffc7e37a884ced4d34088a6b6c507fd88c2 (patch)
treec7c3a4b162b2c1c58b0056e06534b3ccb8c88ca4 /sapi
parentb336af29e11fbb31d2737cb7f2e42149e8de4208 (diff)
parentbae56a87f81b91cd815604b0f404f616b0d73c2b (diff)
downloadphp-git-fd518ffc7e37a884ced4d34088a6b6c507fd88c2.tar.gz
Merge remote-tracking branch 'origin/PHP-5.3' into PHP-5.4
* origin/PHP-5.3: Fixed bug #61546 (functions related to current script failed when chdir() in cli sapi). - BFN Conflicts: sapi/cli/php_cli.c
Diffstat (limited to 'sapi')
-rw-r--r--sapi/cli/php_cli.c11
-rw-r--r--sapi/cli/tests/bug61546.phpt22
2 files changed, 30 insertions, 3 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 801e53ba24..205b9db3fe 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -662,7 +662,7 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */
int php_optind = 1, orig_optind = 1;
char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
char *arg_free=NULL, **arg_excp=&arg_free;
- char *script_file=NULL;
+ char *script_file=NULL, *translated_path = NULL;
int interactive=0;
int lineno = 0;
const char *param_error=NULL;
@@ -927,8 +927,13 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */
if (script_file) {
if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
goto err;
+ } else {
+ char real_path[MAXPATHLEN];
+ if (VCWD_REALPATH(script_file, real_path)) {
+ translated_path = strdup(real_path);
+ }
+ script_filename = script_file;
}
- script_filename = script_file;
} else {
/* We could handle PHP_MODE_PROCESS_STDIN in a different manner */
/* here but this would make things only more complicated. And it */
@@ -947,7 +952,7 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */
SG(request_info).argc=argc-php_optind+1;
arg_excp = argv+php_optind-1;
arg_free = argv[php_optind-1];
- SG(request_info).path_translated = (char*)file_handle.filename;
+ SG(request_info).path_translated = translated_path? translated_path: (char*)file_handle.filename;
argv[php_optind-1] = (char*)file_handle.filename;
SG(request_info).argv=argv+php_optind-1;
diff --git a/sapi/cli/tests/bug61546.phpt b/sapi/cli/tests/bug61546.phpt
new file mode 100644
index 0000000000..2cd690f65c
--- /dev/null
+++ b/sapi/cli/tests/bug61546.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #61546 (functions related to current script failed when chdir() in cli sapi)
+--FILE--
+<?php
+$php = getenv("TEST_PHP_EXECUTABLE");
+$test_code = <<<PHP
+<?php
+chdir('..');
+var_dump(get_current_user() != "");
+chdir('..');
+var_dump(getmyinode() != false);
+var_dump(getlastmod() != false);
+PHP;
+
+file_put_contents("bug61546_sub.php", $test_code);
+system($php . ' -n bug61546_sub.php');
+unlink("bug61546_sub.php");
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)