From 4a3a2d4a55b3a62326d5fa74b360ee6d58bae748 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 9 Feb 2023 20:51:17 +0100 Subject: [PATCH 1/2] Fix GH-10489: run-tests.php does not escape path when building cmd Multiple tests had to be changed to escape the arguments in shell commands. Some tests are skipped because they behave differently with spaces in the path versus without. One notable example of this is the hashbang test which does not work because spaces in hashbangs paths are not supported in Linux. --- Zend/tests/bug40236.phpt | 4 ++-- Zend/tests/bug60978.phpt | 3 +-- ext/com_dotnet/tests/bug77578.phpt | 4 ++-- ext/mbstring/tests/gh7902.phpt | 4 +++- ext/simplexml/tests/bug79971_1.phpt | 4 +++- .../tests/directory/bug74589_utf8.phpt | 5 ++-- ext/standard/tests/file/bug22414.phpt | 11 ++++----- ext/standard/tests/file/bug26615.phpt | 4 ++-- ext/standard/tests/file/bug26938.phpt | 2 +- ext/standard/tests/file/bug60120.phpt | 9 +++---- ext/standard/tests/file/mkdir-002.phpt | 3 ++- .../tests/file/popen_pclose_basic.phpt | 5 ++-- ext/standard/tests/file/proc_open01.phpt | 2 +- .../file/windows_mb_path/bug75063_cp1251.phpt | 2 +- .../file/windows_mb_path/bug75063_utf8.phpt | 2 +- .../tests/general_functions/bug69646.phpt | 2 +- .../tests/general_functions/bug70018.phpt | 3 ++- .../general_functions/proc_open-mb0.phpt | 5 ++-- .../general_functions/proc_open-mb1.phpt | 5 ++-- .../general_functions/proc_open_pipes1.phpt | 4 ++-- .../general_functions/proc_open_pipes2.phpt | 4 ++-- .../general_functions/proc_open_pipes3.phpt | 11 +++++---- .../tests/ini_info/php_ini_loaded_file.phpt | 4 ++-- .../tests/ini_info/php_ini_scanned_files.phpt | 2 +- ext/standard/tests/misc/bug79410.phpt | 2 +- ext/standard/tests/streams/bug46024.phpt | 5 ++-- ext/standard/tests/streams/bug70198.phpt | 3 ++- ext/standard/tests/streams/bug78883.phpt | 2 +- .../streams/proc_open_bug51800_right.phpt | 4 ++-- .../streams/proc_open_bug51800_right2.phpt | 4 ++-- .../tests/streams/proc_open_bug60120.phpt | 2 +- .../tests/streams/proc_open_bug64438.phpt | 4 ++-- .../tests/streams/proc_open_bug69900.phpt | 2 +- run-tests.php | 24 +++++++++++++------ sapi/cgi/tests/bug75574_utf8.phpt | 2 +- sapi/cgi/tests/include.inc | 3 ++- sapi/cli/tests/001.phpt | 2 +- sapi/cli/tests/002-unix.phpt | 2 +- sapi/cli/tests/002.phpt | 2 +- sapi/cli/tests/003-2.phpt | 6 ++--- sapi/cli/tests/003.phpt | 2 +- sapi/cli/tests/004.phpt | 2 +- sapi/cli/tests/005.phpt | 8 +++---- sapi/cli/tests/006.phpt | 2 +- sapi/cli/tests/007.phpt | 2 +- sapi/cli/tests/008.phpt | 2 +- sapi/cli/tests/009.phpt | 2 +- sapi/cli/tests/010-2.phpt | 5 ++-- sapi/cli/tests/010.phpt | 6 +++-- sapi/cli/tests/011.phpt | 9 +++---- sapi/cli/tests/012-2.phpt | 24 +++++++++---------- sapi/cli/tests/012.phpt | 18 +++++++------- sapi/cli/tests/013.phpt | 9 +++---- sapi/cli/tests/014.phpt | 7 +++--- sapi/cli/tests/015.phpt | 10 ++++---- sapi/cli/tests/016.phpt | 4 ++-- sapi/cli/tests/017.phpt | 2 +- sapi/cli/tests/018.phpt | 4 ++-- sapi/cli/tests/019.phpt | 4 ++-- sapi/cli/tests/020.phpt | 6 ++--- sapi/cli/tests/021.phpt | 4 ++++ sapi/cli/tests/022.phpt | 2 +- sapi/cli/tests/023.phpt | 5 ++-- sapi/cli/tests/argv_mb.phpt | 5 ++-- sapi/cli/tests/bug61546.phpt | 2 +- sapi/cli/tests/bug62294.phpt | 4 ++-- sapi/cli/tests/bug64529.phpt | 2 +- sapi/cli/tests/bug65275.phpt | 4 ++-- sapi/cli/tests/bug71624.phpt | 7 +++--- sapi/cli/tests/bug74600.phpt | 5 ++-- sapi/cli/tests/bug78323.phpt | 2 +- .../tests/sapi_windows_set_ctrl_handler.phpt | 2 +- sapi/phpdbg/tests/bug73615.phpt | 2 +- tests/basic/bug71273.phpt | 2 +- tests/run-test/extensions-shared.phpt | 2 +- 75 files changed, 191 insertions(+), 160 deletions(-) diff --git a/Zend/tests/bug40236.phpt b/Zend/tests/bug40236.phpt index 35ed84066b8b..7ed298c1eed6 100644 --- a/Zend/tests/bug40236.phpt +++ b/Zend/tests/bug40236.phpt @@ -6,8 +6,8 @@ if (extension_loaded("readline")) die("skip Test doesn't support readline"); ?> --FILE-- --EXPECT-- diff --git a/Zend/tests/bug60978.phpt b/Zend/tests/bug60978.phpt index 5dc6fe31e716..2d83d2a213e6 100644 --- a/Zend/tests/bug60978.phpt +++ b/Zend/tests/bug60978.phpt @@ -2,8 +2,7 @@ Bug #60978 (exit code incorrect) --FILE-- --EXPECT-- diff --git a/ext/com_dotnet/tests/bug77578.phpt b/ext/com_dotnet/tests/bug77578.phpt index 653a16123218..a820935d5d77 100644 --- a/ext/com_dotnet/tests/bug77578.phpt +++ b/ext/com_dotnet/tests/bug77578.phpt @@ -6,8 +6,8 @@ com_dotnet --INI-- sendmail_path={MAIL:{PWD}/gh7902.eml} diff --git a/ext/simplexml/tests/bug79971_1.phpt b/ext/simplexml/tests/bug79971_1.phpt index 1097d74bb29d..2ee07c81822f 100644 --- a/ext/simplexml/tests/bug79971_1.phpt +++ b/ext/simplexml/tests/bug79971_1.phpt @@ -1,8 +1,10 @@ --TEST-- Bug #79971 (special character is breaking the path in xml function) +--EXTENSIONS-- +simplexml --SKIPIF-- --FILE-- --EXPECTF-- diff --git a/ext/standard/tests/file/bug22414.phpt b/ext/standard/tests/file/bug22414.phpt index 55078568152c..49ac237f1ab6 100644 --- a/ext/standard/tests/file/bug22414.phpt +++ b/ext/standard/tests/file/bug22414.phpt @@ -6,22 +6,21 @@ output_handler= '.$tmpfile ; + $cmd = $php_escaped . $args . ' -r ' . escapeshellarg('passthru("'.$cmd.'");') . ' > '.escapeshellarg($tmpfile); } else { - $cmd = $php . $args . ' -r \"readfile(@getenv(\\\\\\"TEST_PHP_EXECUTABLE\\\\\\")); \"'; - $cmd = $php . $args . ' -r " passthru(\''.$cmd.'\');" > '.$tmpfile ; + $cmd = $php_escaped . $args . ' -r ' . "\"passthru('".addslashes($cmd)."');\"" . ' > '.escapeshellarg($tmpfile); } exec($cmd); diff --git a/ext/standard/tests/file/bug26615.phpt b/ext/standard/tests/file/bug26615.phpt index 8a5df91ec183..2e652fa34390 100644 --- a/ext/standard/tests/file/bug26615.phpt +++ b/ext/standard/tests/file/bug26615.phpt @@ -7,9 +7,9 @@ variables_order=E $out = array(); $status = -1; if (substr(PHP_OS, 0, 3) != 'WIN') { - exec($_ENV['TEST_PHP_EXECUTABLE'].' -n -r \'for($i=1;$i<=5000;$i++) print "$i\n";\' | tr \'\n\' \' \'', $out, $status); + exec($_ENV['TEST_PHP_EXECUTABLE_ESCAPED'].' -n -r \'for($i=1;$i<=5000;$i++) print "$i\n";\' | tr \'\n\' \' \'', $out, $status); } else { - exec($_ENV['TEST_PHP_EXECUTABLE'].' -n -r "for($i=1;$i<=5000;$i++) echo $i,\' \';"', $out, $status); + exec($_ENV['TEST_PHP_EXECUTABLE_ESCAPED'].' -n -r "for($i=1;$i<=5000;$i++) echo $i,\' \';"', $out, $status); } print_r($out); ?> diff --git a/ext/standard/tests/file/bug26938.phpt b/ext/standard/tests/file/bug26938.phpt index 13732c03f630..eec537d2d970 100644 --- a/ext/standard/tests/file/bug26938.phpt +++ b/ext/standard/tests/file/bug26938.phpt @@ -4,7 +4,7 @@ Bug #26938 (exec does not read consecutive long lines correctly) '); $ds = array( @@ -19,7 +20,7 @@ $ds = array( ); $p = proc_open( - "$php -n $f テストマルチバイト・パス füße карамба", + "$php -n $f_escaped テストマルチバイト・パス füße карамба", $ds, $pipes, NULL, diff --git a/ext/standard/tests/general_functions/proc_open-mb1.phpt b/ext/standard/tests/general_functions/proc_open-mb1.phpt index 8a735cf306ed..057979e604c7 100644 --- a/ext/standard/tests/general_functions/proc_open-mb1.phpt +++ b/ext/standard/tests/general_functions/proc_open-mb1.phpt @@ -7,9 +7,10 @@ if (!function_exists("proc_open")) echo "skip proc_open() is not available"; --FILE-- '); $ds = array( @@ -19,7 +20,7 @@ $ds = array( ); $p = proc_open( - "$php -n $f テストマルチバイト・パス füße карамба", + "$php -n $f_escaped テストマルチバイト・パス füße карамба", $ds, $pipes ); diff --git a/ext/standard/tests/general_functions/proc_open_pipes1.phpt b/ext/standard/tests/general_functions/proc_open_pipes1.phpt index 076b8c941e2c..9822607c6f7e 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes1.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes1.phpt @@ -7,8 +7,8 @@ for ($i = 3; $i<= 30; $i++) { $spec[$i] = array('pipe', 'w'); } -$php = getenv("TEST_PHP_EXECUTABLE"); -$callee = __DIR__ . "/proc_open_pipes_sleep.inc"; +$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); +$callee = escapeshellarg(__DIR__ . "/proc_open_pipes_sleep.inc"); proc_open("$php -n $callee", $spec, $pipes); var_dump(count($spec)); diff --git a/ext/standard/tests/general_functions/proc_open_pipes2.phpt b/ext/standard/tests/general_functions/proc_open_pipes2.phpt index 3c1cf9695592..c147a2f37646 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes2.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes2.phpt @@ -5,8 +5,8 @@ proc_open() with no pipes $spec = array(); -$php = getenv("TEST_PHP_EXECUTABLE"); -$callee = __DIR__ . "/proc_open_pipes_sleep.inc"; +$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); +$callee = escapeshellarg(__DIR__ . "/proc_open_pipes_sleep.inc"); proc_open("$php -n $callee", $spec, $pipes); var_dump(count($spec)); diff --git a/ext/standard/tests/general_functions/proc_open_pipes3.phpt b/ext/standard/tests/general_functions/proc_open_pipes3.phpt index f5801ad63e43..1ee42904a058 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes3.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes3.phpt @@ -7,25 +7,26 @@ for ($i = 3; $i<= 5; $i++) { $spec[$i] = array('pipe', 'w'); } -$php = getenv("TEST_PHP_EXECUTABLE"); +$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); $callee = __DIR__ . "/proc_open_pipes_sleep.inc"; +$callee_escaped = escapeshellarg($callee); $spec[$i] = array('pi'); -proc_open("$php -n $callee", $spec, $pipes); +proc_open("$php -n $callee_escaped", $spec, $pipes); $spec[$i] = 1; try { - proc_open("$php -n $callee", $spec, $pipes); + proc_open("$php -n $callee_escaped", $spec, $pipes); } catch (ValueError $exception) { echo $exception->getMessage() . "\n"; } $spec[$i] = array('pipe', "test"); -proc_open("$php -n $callee", $spec, $pipes); +proc_open("$php -n $callee_escaped", $spec, $pipes); var_dump($pipes); $spec[$i] = array('file', "test", "z"); -proc_open("$php -n $callee", $spec, $pipes); +proc_open("$php -n $callee_escaped", $spec, $pipes); var_dump($pipes); echo "END\n"; diff --git a/ext/standard/tests/ini_info/php_ini_loaded_file.phpt b/ext/standard/tests/ini_info/php_ini_loaded_file.phpt index b4ad617f9fec..1fce24e67fe4 100644 --- a/ext/standard/tests/ini_info/php_ini_loaded_file.phpt +++ b/ext/standard/tests/ini_info/php_ini_loaded_file.phpt @@ -3,14 +3,14 @@ php_ini_loaded_file() function --FILE-- --EXPECTREGEX-- bool\(false\) diff --git a/ext/standard/tests/ini_info/php_ini_scanned_files.phpt b/ext/standard/tests/ini_info/php_ini_scanned_files.phpt index 27d2bebadf12..6f750584fd71 100644 --- a/ext/standard/tests/ini_info/php_ini_scanned_files.phpt +++ b/ext/standard/tests/ini_info/php_ini_scanned_files.phpt @@ -3,7 +3,7 @@ php_ini_scanned_files() function --FILE-- --EXPECT-- diff --git a/ext/standard/tests/streams/bug46024.phpt b/ext/standard/tests/streams/bug46024.phpt index 5a712dcb6b92..79078890ce1a 100644 --- a/ext/standard/tests/streams/bug46024.phpt +++ b/ext/standard/tests/streams/bug46024.phpt @@ -2,17 +2,16 @@ Bug #46024 stream_select() doesn't return the correct number --SKIPIF-- --FILE-- array('pipe', 'r'), 1 => array('pipe', 'w')) ,$pipes, __DIR__, array(), array() ); diff --git a/ext/standard/tests/streams/bug70198.phpt b/ext/standard/tests/streams/bug70198.phpt index fc9c30f6fe34..0e122b66e8e7 100644 --- a/ext/standard/tests/streams/bug70198.phpt +++ b/ext/standard/tests/streams/bug70198.phpt @@ -17,6 +17,7 @@ server $srv_addr = "tcp://127.0.0.1:8964"; $srv_fl = __DIR__ . "/bug70198_svr_" . md5(uniqid()) . ".php"; +$srv_fl_escaped = escapeshellarg($srv_fl); $srv_fl_cont = << array("file", "stderr.txt", "ab") ); $pipes = []; -$cmd = 'cmd.exe "/c START ^"^" /WAIT ' . PHP_BINARY . ' -r ^"var_dump(fgets(STDIN));"'; +$cmd = 'cmd.exe "/c START ^"^" /WAIT ' . getenv('TEST_PHP_EXECUTABLE_ESCAPED') . ' -r ^"var_dump(fgets(STDIN));"'; $proc = proc_open($cmd, $descriptorspec, $pipes); var_dump(is_resource($proc)); $pid = proc_get_status($proc)['pid']; diff --git a/ext/standard/tests/streams/proc_open_bug51800_right.phpt b/ext/standard/tests/streams/proc_open_bug51800_right.phpt index 1c889f6e9877..ba68fa2a208f 100644 --- a/ext/standard/tests/streams/proc_open_bug51800_right.phpt +++ b/ext/standard/tests/streams/proc_open_bug51800_right.phpt @@ -9,8 +9,8 @@ if (strpos(PHP_OS, 'FreeBSD') !== false) { --FILE-- array("pipe", "r"),1 => array("pipe", "w")); $pipes = array(); -$process = proc_open(PHP_BINARY.' -n -f ' . $fl, $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true)); +$process = proc_open(getenv('TEST_PHP_EXECUTABLE_ESCAPED').' -n -f ' . escapeshellarg($fl), $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true)); $moreThanLimit = 0; for($i = 0; $i < 10; $i++){ diff --git a/run-tests.php b/run-tests.php index 9b892327c8db..2e4cab7ee537 100755 --- a/run-tests.php +++ b/run-tests.php @@ -678,10 +678,16 @@ function main(): void putenv("TEST_PHP_EXECUTABLE=$php"); $environment['TEST_PHP_EXECUTABLE'] = $php; + putenv("TEST_PHP_EXECUTABLE_ESCAPED=" . escapeshellarg($php)); + $environment['TEST_PHP_EXECUTABLE_ESCAPED'] = escapeshellarg($php); putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi"); $environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi; + putenv("TEST_PHP_CGI_EXECUTABLE_ESCAPED=" . escapeshellarg($php_cgi)); + $environment['TEST_PHP_CGI_EXECUTABLE_ESCAPED'] = escapeshellarg($php_cgi); putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg"); $environment['TEST_PHPDBG_EXECUTABLE'] = $phpdbg; + putenv("TEST_PHPDBG_EXECUTABLE_ESCAPED=" . escapeshellarg($phpdbg)); + $environment['TEST_PHPDBG_EXECUTABLE_ESCAPED'] = escapeshellarg($phpdbg); if ($conf_passed !== null) { if (IS_WINDOWS) { @@ -831,6 +837,7 @@ function verify_config(): void function write_information(): void { global $php, $php_cgi, $phpdbg, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test, $valgrind, $no_file_cache; + $php_escaped = escapeshellarg($php); // Get info from php $info_file = __DIR__ . '/run-test-info.php'; @@ -846,11 +853,12 @@ function write_information(): void $info_params = []; settings2array($ini_overwrites, $info_params); $info_params = settings2params($info_params); - $php_info = shell_exec("$php $pass_options $info_params $no_file_cache \"$info_file\""); - define('TESTED_PHP_VERSION', shell_exec("$php -n -r \"echo PHP_VERSION;\"")); + $php_info = shell_exec("$php_escaped $pass_options $info_params $no_file_cache \"$info_file\""); + define('TESTED_PHP_VERSION', shell_exec("$php_escaped -n -r \"echo PHP_VERSION;\"")); if ($php_cgi && $php != $php_cgi) { - $php_info_cgi = shell_exec("$php_cgi $pass_options $info_params $no_file_cache -q \"$info_file\""); + $php_cgi_escaped = escapeshellarg($php_cgi); + $php_info_cgi = shell_exec("$php_cgi_escaped $pass_options $info_params $no_file_cache -q \"$info_file\""); $php_info_sep = "\n---------------------------------------------------------------------"; $php_cgi_info = "$php_info_sep\nPHP : $php_cgi $php_info_cgi$php_info_sep"; } else { @@ -858,7 +866,8 @@ function write_information(): void } if ($phpdbg) { - $phpdbg_info = shell_exec("$phpdbg $pass_options $info_params $no_file_cache -qrr \"$info_file\""); + $phpdbg_escaped = escapeshellarg($phpdbg); + $phpdbg_info = shell_exec("$phpdbg_escaped $pass_options $info_params $no_file_cache -qrr \"$info_file\""); $php_info_sep = "\n---------------------------------------------------------------------"; $phpdbg_info = "$php_info_sep\nPHP : $phpdbg $phpdbg_info$php_info_sep"; } else { @@ -884,7 +893,7 @@ function write_information(): void } echo implode(',', $exts); PHP); - $extensionsNames = explode(',', shell_exec("$php $pass_options $info_params $no_file_cache \"$info_file\"")); + $extensionsNames = explode(',', shell_exec("$php_escaped $pass_options $info_params $no_file_cache \"$info_file\"")); $exts_to_test = array_unique(remap_loaded_extensions_names($extensionsNames)); // check for extensions that need special handling and regenerate $info_params_ex = [ @@ -1838,6 +1847,7 @@ function run_test(string $php, $file, array $env): string $org_file = $file; $orig_php = $php; + $php = escapeshellarg($php); $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'] ?? null; $phpdbg = $env['TEST_PHPDBG_EXECUTABLE'] ?? null; @@ -1898,7 +1908,7 @@ function run_test(string $php, $file, array $env): string if (!$php_cgi) { return skip_test($tested, $tested_file, $shortname, 'CGI not available'); } - $php = $php_cgi . ' -C '; + $php = escapeshellarg($php_cgi) . ' -C '; $uses_cgi = true; if ($num_repeats > 1) { return skip_test($tested, $tested_file, $shortname, 'CGI does not support --repeat'); @@ -1909,7 +1919,7 @@ function run_test(string $php, $file, array $env): string $extra_options = ''; if ($test->hasSection('PHPDBG')) { if (isset($phpdbg)) { - $php = $phpdbg . ' -qIb'; + $php = escapeshellarg($phpdbg) . ' -qIb'; // Additional phpdbg command line options for sections that need to // be run straight away. For example, EXTENSIONS, SKIPIF, CLEAN. diff --git a/sapi/cgi/tests/bug75574_utf8.phpt b/sapi/cgi/tests/bug75574_utf8.phpt index 9cbd51abfbd9..76d2d8c1f4cd 100644 --- a/sapi/cgi/tests/bug75574_utf8.phpt +++ b/sapi/cgi/tests/bug75574_utf8.phpt @@ -13,7 +13,7 @@ include "skipif.inc"; include "include.inc"; -$php = get_cgi_path(); +$php = escapeshellarg(get_cgi_path()); reset_env_vars(); $fn = __DIR__ . DIRECTORY_SEPARATOR . md5(uniqid()); diff --git a/sapi/cgi/tests/include.inc b/sapi/cgi/tests/include.inc index de526723df0f..d155edf4ba20 100644 --- a/sapi/cgi/tests/include.inc +++ b/sapi/cgi/tests/include.inc @@ -3,12 +3,13 @@ function get_cgi_path() /* {{{ */ { $php = getenv("TEST_PHP_EXECUTABLE"); + $php_escaped = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); $cli = false; $cgi = false; if (file_exists($php) && is_executable($php)) { - $version = `$php -n -v`; + $version = `$php_escaped -n -v`; if (strstr($version, "(cli)")) { /* that's cli */ $cli = true; diff --git a/sapi/cli/tests/001.phpt b/sapi/cli/tests/001.phpt index ede63ffb033e..aced33623eff 100644 --- a/sapi/cli/tests/001.phpt +++ b/sapi/cli/tests/001.phpt @@ -5,7 +5,7 @@ version string --FILE-- --EXPECT-- diff --git a/sapi/cli/tests/003.phpt b/sapi/cli/tests/003.phpt index 63e812d4a7cd..20bf61a247bf 100644 --- a/sapi/cli/tests/003.phpt +++ b/sapi/cli/tests/003.phpt @@ -10,7 +10,7 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 1f2af9c6b635..9d693f65969b 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -15,7 +15,7 @@ date.timezone=UTC --FILE-- --CLEAN-- diff --git a/sapi/cli/tests/011.phpt b/sapi/cli/tests/011.phpt index 24eb9fc2dfff..bd61b260f5a9 100644 --- a/sapi/cli/tests/011.phpt +++ b/sapi/cli/tests/011.phpt @@ -5,9 +5,10 @@ syntax check --FILE-- diff --git a/sapi/cli/tests/012.phpt b/sapi/cli/tests/012.phpt index 08ec4ecb1c73..be21b3d99e87 100644 --- a/sapi/cli/tests/012.phpt +++ b/sapi/cli/tests/012.phpt @@ -5,16 +5,16 @@ invalid arguments and error messages --FILE-- diff --git a/sapi/cli/tests/013.phpt b/sapi/cli/tests/013.phpt index 0684b8d0573c..345a489403ac 100644 --- a/sapi/cli/tests/013.phpt +++ b/sapi/cli/tests/013.phpt @@ -10,14 +10,15 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- &1 | grep Usage:`; +echo `$php -n --version | grep built:`; +echo `echo "&1 | grep Usage:`; echo "Done\n"; ?> diff --git a/sapi/cli/tests/016.phpt b/sapi/cli/tests/016.phpt index c7ce07913f15..544633f592f6 100644 --- a/sapi/cli/tests/016.phpt +++ b/sapi/cli/tests/016.phpt @@ -11,7 +11,7 @@ if (readline_info('done') === NULL) { ?> --FILE-- $code) { echo "\n--------------\nSnippet no. $key:\n--------------\n"; $code = escapeshellarg($code); - echo `echo $code | "$php" -a`, "\n"; + echo `echo $code | $php -a`, "\n"; } echo "\nDone\n"; diff --git a/sapi/cli/tests/017.phpt b/sapi/cli/tests/017.phpt index d2d37b18589a..6adbf195e2ee 100644 --- a/sapi/cli/tests/017.phpt +++ b/sapi/cli/tests/017.phpt @@ -11,7 +11,7 @@ if (readline_info('done') !== NULL) { ?> --FILE-- diff --git a/sapi/cli/tests/019.phpt b/sapi/cli/tests/019.phpt index e8404d835e5e..0f5a66c871ef 100644 --- a/sapi/cli/tests/019.phpt +++ b/sapi/cli/tests/019.phpt @@ -10,10 +10,10 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- diff --git a/sapi/cli/tests/020.phpt b/sapi/cli/tests/020.phpt index fb7bcb4e7b5f..3ccd6a83d3b3 100644 --- a/sapi/cli/tests/020.phpt +++ b/sapi/cli/tests/020.phpt @@ -10,11 +10,11 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- diff --git a/sapi/cli/tests/021.phpt b/sapi/cli/tests/021.phpt index 837f64109d03..9a24ec454a98 100644 --- a/sapi/cli/tests/021.phpt +++ b/sapi/cli/tests/021.phpt @@ -7,6 +7,10 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { die ("skip not for Windows"); } +if (str_contains(getenv('TEST_PHP_EXECUTABLE'), " ")) { + die("skip shebang cannot have spaces in its path"); +} + if (strlen("#!".getenv('TEST_PHP_EXECUTABLE')) > 127) { die ("skip shebang is too long, see http://www.in-ulm.de/~mascheck/various/shebang/#results"); } diff --git a/sapi/cli/tests/022.phpt b/sapi/cli/tests/022.phpt index 40c226535184..1afb5fc371a7 100644 --- a/sapi/cli/tests/022.phpt +++ b/sapi/cli/tests/022.phpt @@ -7,7 +7,7 @@ if (substr(PHP_OS, 0, 3) == "WIN") die("skip non windows test"); ?> --FILE-- --FILE-- array("pipe", "w"), ); $pipes = array(); -$proc = proc_open("$php -c $ini_file -r 'echo ini_get(\"memory_limit\");'", $desc, $pipes); +$proc = proc_open("$php -c $ini_file_escaped -r 'echo ini_get(\"memory_limit\");'", $desc, $pipes); if (!$proc) { exit(1); } diff --git a/sapi/cli/tests/argv_mb.phpt b/sapi/cli/tests/argv_mb.phpt index 5ed5cef34378..f7f6dd49081b 100644 --- a/sapi/cli/tests/argv_mb.phpt +++ b/sapi/cli/tests/argv_mb.phpt @@ -7,12 +7,13 @@ include "skipif.inc"; --FILE-- "); -var_dump(`$php -n $argv_fl 多字节字符串 マルチバイト文字列 многобайтоваястрока flerbytesträng`); +var_dump(`$php -n $argv_fl_escaped 多字节字符串 マルチバイト文字列 многобайтоваястрока flerbytesträng`); @unlink($argv_fl); diff --git a/sapi/cli/tests/bug61546.phpt b/sapi/cli/tests/bug61546.phpt index 071edb722442..67b531472174 100644 --- a/sapi/cli/tests/bug61546.phpt +++ b/sapi/cli/tests/bug61546.phpt @@ -11,7 +11,7 @@ Bug #61546 (functions related to current script failed when chdir() in cli sapi) // the ext/standard/tests/file/statpage.phpt test also tests getmyinode() returns an integer and will // pass even if that integer is 0. on Windows, the getmyinode() call in statpage.phpt returns 0 and // passes on Windows. -$php = getenv("TEST_PHP_EXECUTABLE"); +$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); $test_code = << diff --git a/sapi/cli/tests/bug64529.phpt b/sapi/cli/tests/bug64529.phpt index dd7b809cfbc5..44df61020e47 100644 --- a/sapi/cli/tests/bug64529.phpt +++ b/sapi/cli/tests/bug64529.phpt @@ -18,7 +18,7 @@ if ($ret) { --FILE-- diff --git a/sapi/cli/tests/bug71624.phpt b/sapi/cli/tests/bug71624.phpt index 8b82ebab58c9..83f48cf921c5 100644 --- a/sapi/cli/tests/bug71624.phpt +++ b/sapi/cli/tests/bug71624.phpt @@ -7,9 +7,10 @@ include "skipif.inc"; --FILE-- --FILE-- array("pipe", "w"), ); $pipes = array(); -$proc = proc_open("$php -c $ini_file -r 'echo \"okey\";'", $desc, $pipes); +$proc = proc_open("$php -c $ini_file_escaped -r 'echo \"okey\";'", $desc, $pipes); if (!$proc) { exit(1); } diff --git a/sapi/cli/tests/bug78323.phpt b/sapi/cli/tests/bug78323.phpt index 02b18e02a214..d353281a0e86 100644 --- a/sapi/cli/tests/bug78323.phpt +++ b/sapi/cli/tests/bug78323.phpt @@ -6,7 +6,7 @@ include "skipif.inc"; ?> --FILE-- ["pipe", "r"], 1 => ["pipe", "w"]]; $proc = proc_open($cmd, $spec, $pipes, NULL, NULL, ["bypass_shell" => true, "create_process_group" => true]); diff --git a/sapi/phpdbg/tests/bug73615.phpt b/sapi/phpdbg/tests/bug73615.phpt index e5fccef0a85c..2208cdebf707 100644 --- a/sapi/phpdbg/tests/bug73615.phpt +++ b/sapi/phpdbg/tests/bug73615.phpt @@ -7,7 +7,7 @@ if (!getenv('TEST_PHPDBG_EXECUTABLE')) die("SKIP: No TEST_PHPDBG_EXECUTABLE spec --FILE-- &1"; + $cmd = getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n -d html_errors=on -d extension_dir=a//w -d extension=php_kartoffelbrei.dll -v 2>&1"; $out = shell_exec($cmd); var_dump(preg_match(",.+a[\\/].+[\\/]w.php_kartoffelbrei.dll.+,s", $out)); diff --git a/tests/run-test/extensions-shared.phpt b/tests/run-test/extensions-shared.phpt index e8d9b52aa98a..2bbe8b767655 100644 --- a/tests/run-test/extensions-shared.phpt +++ b/tests/run-test/extensions-shared.phpt @@ -4,7 +4,7 @@ phpt EXTENSIONS directive - shared module openssl --SKIPIF-- Date: Sun, 19 Feb 2023 21:06:43 +0100 Subject: [PATCH 2/2] honor cmd quotes on Windows in run-tests.php --- run-tests.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run-tests.php b/run-tests.php index 2e4cab7ee537..6ff9041a5d08 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1172,6 +1172,13 @@ function system_with_timeout( ) { global $valgrind; + // when proc_open cmd is passed as a string (without bypass_shell=true option) the cmd goes thru shell + // and on Windows quotes are discarded, this is a fix to honor the quotes and allow values containing + // spaces like '"C:\Program Files\PHP\php.exe"' to be passed as 1 argument correctly + if (IS_WINDOWS) { + $commandline = 'start "" /b /wait ' . $commandline; + } + $data = ''; $bin_env = [];