Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ int main(int argc, char *argv[])
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 = file_handle.filename;
SG(request_info).path_translated = tsrm_realpath(file_handle.filename, NULL TSRMLS_CC);
argv[php_optind-1] = file_handle.filename;
SG(request_info).argv=argv+php_optind-1;

Expand Down
10 changes: 10 additions & 0 deletions sapi/cli/tests/bug61546.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
$func = $argv[1];

var_dump(chdir(".."));

if ($func == 'get_current_user') {
var_dump(get_current_user() !== "");
} else {
var_dump($func() !== false);
}
44 changes: 44 additions & 0 deletions sapi/cli/tests/bug61546.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
Bug #61546 (functions related to current script failed when chdir() in cli sapi)
--FILE--
<?php

function test_func($func) {
$php = getenv("TEST_PHP_EXECUTABLE");
$test_file = pathinfo(__FILE__, PATHINFO_FILENAME) . '.inc';

$desc = array(
0 => STDIN,
1 => STDOUT,
2 => STDERR,
);

/*
* The auto test tool will pass absolute path of the current script to php,
* so use proc_open to execute script as relative filename.
*/
proc_open("$php -n " . escapeshellarg($test_file) . " $func", $desc, $pipes, dirname(__FILE__));
}

test_func('get_current_user');
test_func('getmyinode');
test_func('getlastmod');

/*
* getmyuid and getmygid will not be affected because those two functions have fallback
* when current script can't be found such as run as php -r. listed here just for testing
*/
test_func('getmyuid');
test_func('getmygid');
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)