From ca5fbcf697d6c7efd7a678a93b0feec86a27889c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= Date: Thu, 21 Mar 2024 15:40:44 -0300 Subject: [PATCH] tests: do not use a shell in proc_open if not really needed It is seldom that the tests are used to perform operations that require a shell. remove all implicit shell uses where appropiate. --- ext/curl/tests/curl_setopt_ssl.phpt | 17 ++++++++++++++++- .../tests/stream_server_reneg_limit.phpt | 7 ++++++- .../tests/waiting_on_sigchild_pcntl_wait.phpt | 2 +- ext/standard/tests/file/proc_open01.phpt | 4 ++-- .../tests/general_functions/bug34794.phpt | 4 ++-- .../tests/general_functions/bug44667.phpt | 2 +- .../tests/general_functions/gh10239_1.phpt | 2 +- .../tests/general_functions/gh10239_2.phpt | 2 +- .../tests/general_functions/gh12655.phpt | 2 +- .../tests/general_functions/proc_open.phpt | 2 +- .../general_functions/proc_open_pipes1.phpt | 6 +++--- .../general_functions/proc_open_pipes2.phpt | 6 +++--- .../general_functions/proc_open_pipes3.phpt | 11 +++++------ ext/standard/tests/streams/bug46024.phpt | 8 ++++---- ext/standard/tests/streams/bug60602.phpt | 2 +- ext/standard/tests/streams/bug70198.phpt | 2 +- ext/standard/tests/streams/bug72853.phpt | 2 +- .../tests/streams/proc_open_bug60120.phpt | 2 +- .../tests/streams/proc_open_bug69900.phpt | 2 +- .../tests/streams/stream_cast_loses_data.phpt | 2 +- sapi/cli/tests/022.phpt | 4 ++-- sapi/cli/tests/023.phpt | 5 ++--- .../tests/sapi_windows_set_ctrl_handler.phpt | 2 +- 23 files changed, 58 insertions(+), 40 deletions(-) diff --git a/ext/curl/tests/curl_setopt_ssl.phpt b/ext/curl/tests/curl_setopt_ssl.phpt index 11d8fff702a88..b7aebf2aaa854 100644 --- a/ext/curl/tests/curl_setopt_ssl.phpt +++ b/ext/curl/tests/curl_setopt_ssl.phpt @@ -61,7 +61,22 @@ if ($serverCert === false $port = 14430; // set up local server -$cmd = "openssl s_server -key $serverKeyPath -cert $serverCertPath -accept $port -www -CAfile $clientCertPath -verify_return_error -Verify 1"; +$cmd = [ + 'openssl', + 's_server', + '-key', + $serverKeyPath, + '-cert', + $serverCertPath, + '-accept', + $port, + '-www', + '-CAfile', + $clientCertPath, + '-verify_return_error', + '-Verify', + 1 +]; $process = proc_open($cmd, [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes); if ($process === false) { diff --git a/ext/openssl/tests/stream_server_reneg_limit.phpt b/ext/openssl/tests/stream_server_reneg_limit.phpt index d661e9dc42331..ca613db0cb8b4 100644 --- a/ext/openssl/tests/stream_server_reneg_limit.phpt +++ b/ext/openssl/tests/stream_server_reneg_limit.phpt @@ -73,7 +73,12 @@ $serverCode = sprintf($serverCode, $certFile); $clientCode = <<<'CODE' phpt_wait(); - $cmd = 'openssl s_client -connect 127.0.0.1:64321'; + $cmd = [ + 'openssl', + 's_client', + '-connect', + '127.0.0.1:64321' + ]; $descriptorSpec = [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]]; $process = proc_open($cmd, $descriptorSpec, $pipes); diff --git a/ext/pcntl/tests/waiting_on_sigchild_pcntl_wait.phpt b/ext/pcntl/tests/waiting_on_sigchild_pcntl_wait.phpt index 482888cfadd97..a407056325c3f 100644 --- a/ext/pcntl/tests/waiting_on_sigchild_pcntl_wait.phpt +++ b/ext/pcntl/tests/waiting_on_sigchild_pcntl_wait.phpt @@ -22,7 +22,7 @@ pcntl_signal(SIGCHLD, function($sig, $info) use (&$processes) { for ($i = 0; $i <= 5; $i++) { // Sleeping ensures we get to add the process to the list before the signal is invoked. - $process = proc_open('sleep 1', [], $pipes); + $process = proc_open(['sleep', '1'], [], $pipes); $pid = proc_get_status($process)['pid']; $processes[$pid] = $process; } diff --git a/ext/standard/tests/file/proc_open01.phpt b/ext/standard/tests/file/proc_open01.phpt index 5ebfc72351b6d..e393c55b9d431 100644 --- a/ext/standard/tests/file/proc_open01.phpt +++ b/ext/standard/tests/file/proc_open01.phpt @@ -4,12 +4,12 @@ proc_open() regression test 1 (proc_open() leak) array('pipe', 'r'), 1 => array('pipe', 'w')), $pipes, getcwd(), array(), array() ); diff --git a/ext/standard/tests/general_functions/bug34794.phpt b/ext/standard/tests/general_functions/bug34794.phpt index fb95a6267f6e4..a38e10d16f0c0 100644 --- a/ext/standard/tests/general_functions/bug34794.phpt +++ b/ext/standard/tests/general_functions/bug34794.phpt @@ -7,10 +7,10 @@ if (!is_executable('/bin/cat')) echo 'skip cat not found'; --FILE-- array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes1); +$process1 = proc_open(['/bin/cat'], array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes1); echo "Opening process 2\n"; -$process2 = proc_open('/bin/cat', array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes2); +$process2 = proc_open(['/bin/cat'], array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes2); echo "Closing process 1\n"; diff --git a/ext/standard/tests/general_functions/bug44667.phpt b/ext/standard/tests/general_functions/bug44667.phpt index 00c822441663b..65791b19cbb12 100644 --- a/ext/standard/tests/general_functions/bug44667.phpt +++ b/ext/standard/tests/general_functions/bug44667.phpt @@ -12,7 +12,7 @@ $descriptor_spec = array( 1 => array('pipe', 'wb'), ); -$proc = proc_open('cat', $descriptor_spec, $pipes); +$proc = proc_open(['cat'], $descriptor_spec, $pipes); fwrite($pipes[0], 'Hello', 5); fflush($pipes[0]); diff --git a/ext/standard/tests/general_functions/gh10239_1.phpt b/ext/standard/tests/general_functions/gh10239_1.phpt index cc67430fe1d19..0f7d87639d525 100644 --- a/ext/standard/tests/general_functions/gh10239_1.phpt +++ b/ext/standard/tests/general_functions/gh10239_1.phpt @@ -7,7 +7,7 @@ if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); ?> --FILE-- --FILE-- &$d ) // don't do anything, just the fact that we used "&$d" will sink the ship! } -$proc = proc_open(PHP_BINARY, $descriptor_spec, $pipes); +$proc = proc_open([PHP_BINARY], $descriptor_spec, $pipes); echo $proc === false ? "FAILED\n" : "SUCCEEDED\n"; ?> diff --git a/ext/standard/tests/general_functions/proc_open.phpt b/ext/standard/tests/general_functions/proc_open.phpt index cf0bffffb5bcc..bddffef3f7534 100644 --- a/ext/standard/tests/general_functions/proc_open.phpt +++ b/ext/standard/tests/general_functions/proc_open.phpt @@ -14,7 +14,7 @@ $ds = array( ); $cat = proc_open( - "/bin/cat", + ['/bin/cat'], $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 9822607c6f7ef..08b3dabe997f2 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes1.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes1.phpt @@ -7,9 +7,9 @@ for ($i = 3; $i<= 30; $i++) { $spec[$i] = array('pipe', 'w'); } -$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); -$callee = escapeshellarg(__DIR__ . "/proc_open_pipes_sleep.inc"); -proc_open("$php -n $callee", $spec, $pipes); +$php = getenv("TEST_PHP_EXECUTABLE"); +$callee = __DIR__ . "/proc_open_pipes_sleep.inc"; +proc_open([$php, '-n', $callee], $spec, $pipes); var_dump(count($spec)); var_dump($pipes); diff --git a/ext/standard/tests/general_functions/proc_open_pipes2.phpt b/ext/standard/tests/general_functions/proc_open_pipes2.phpt index c147a2f376464..28fea90d75751 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes2.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes2.phpt @@ -5,9 +5,9 @@ proc_open() with no pipes $spec = array(); -$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); -$callee = escapeshellarg(__DIR__ . "/proc_open_pipes_sleep.inc"); -proc_open("$php -n $callee", $spec, $pipes); +$php = getenv("TEST_PHP_EXECUTABLE"); +$callee = __DIR__ . "/proc_open_pipes_sleep.inc"; +proc_open([$php, "-n", $callee], $spec, $pipes); var_dump(count($spec)); var_dump($pipes); diff --git a/ext/standard/tests/general_functions/proc_open_pipes3.phpt b/ext/standard/tests/general_functions/proc_open_pipes3.phpt index 1ee42904a0588..e21df891d054b 100644 --- a/ext/standard/tests/general_functions/proc_open_pipes3.phpt +++ b/ext/standard/tests/general_functions/proc_open_pipes3.phpt @@ -7,26 +7,25 @@ for ($i = 3; $i<= 5; $i++) { $spec[$i] = array('pipe', 'w'); } -$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED"); +$php = getenv("TEST_PHP_EXECUTABLE"); $callee = __DIR__ . "/proc_open_pipes_sleep.inc"; -$callee_escaped = escapeshellarg($callee); $spec[$i] = array('pi'); -proc_open("$php -n $callee_escaped", $spec, $pipes); +proc_open([$php, "-n", $callee], $spec, $pipes); $spec[$i] = 1; try { - proc_open("$php -n $callee_escaped", $spec, $pipes); + proc_open([$php, "-n", $callee], $spec, $pipes); } catch (ValueError $exception) { echo $exception->getMessage() . "\n"; } $spec[$i] = array('pipe', "test"); -proc_open("$php -n $callee_escaped", $spec, $pipes); +proc_open([$php, "-n", $callee], $spec, $pipes); var_dump($pipes); $spec[$i] = array('file', "test", "z"); -proc_open("$php -n $callee_escaped", $spec, $pipes); +proc_open([$php, "-n", $callee], $spec, $pipes); var_dump($pipes); echo "END\n"; diff --git a/ext/standard/tests/streams/bug46024.phpt b/ext/standard/tests/streams/bug46024.phpt index 2785c979e006d..2cdb438b2312a 100644 --- a/ext/standard/tests/streams/bug46024.phpt +++ b/ext/standard/tests/streams/bug46024.phpt @@ -2,7 +2,7 @@ Bug #46024 stream_select() doesn't return the correct number --SKIPIF-- array('pipe', 'r'), 1 => array('pipe', 'w')) - ,$pipes, __DIR__, array(), array() + [getenv('TEST_PHP_EXECUTABLE'), '-n', '-i'], + array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')), + $pipes, __DIR__, array(), array() ); var_dump($proc); if (!$proc) { diff --git a/ext/standard/tests/streams/bug60602.phpt b/ext/standard/tests/streams/bug60602.phpt index b97f6f877a42d..c3ef2e2afcc6f 100644 --- a/ext/standard/tests/streams/bug60602.phpt +++ b/ext/standard/tests/streams/bug60602.phpt @@ -11,7 +11,7 @@ $descs = array( $environment = array('test' => array(1, 2, 3)); -$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls'; +$cmd = [(substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls']; $p = proc_open($cmd, $descs, $pipes, '.', $environment); if (is_resource($p)) { diff --git a/ext/standard/tests/streams/bug70198.phpt b/ext/standard/tests/streams/bug70198.phpt index 0e122b66e8e7d..8b2330ec8cd6d 100644 --- a/ext/standard/tests/streams/bug70198.phpt +++ b/ext/standard/tests/streams/bug70198.phpt @@ -36,7 +36,7 @@ if (!\$socket) { SRV; file_put_contents($srv_fl, $srv_fl_cont); $dummy0 = $dummy1 = array(); -$srv_proc = proc_open(getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n $srv_fl_escaped", $dummy0, $dummy1); +$srv_proc = proc_open([getenv('TEST_PHP_EXECUTABLE'), "-n", $srv_fl], $dummy0, $dummy1); $i = 0; /* wait a bit for the server startup */ diff --git a/ext/standard/tests/streams/bug72853.phpt b/ext/standard/tests/streams/bug72853.phpt index ab06f81e8c8f8..6b1d68836d23f 100644 --- a/ext/standard/tests/streams/bug72853.phpt +++ b/ext/standard/tests/streams/bug72853.phpt @@ -14,7 +14,7 @@ $descs = array( 1 => array('pipe', 'w'), // stdout ); -$p = proc_open("ls", $descs, $pipes, '.', NULL, NULL); +$p = proc_open(['ls'], $descs, $pipes, '.', NULL, NULL); stream_set_blocking($pipes[1], false); var_dump(stream_get_meta_data($pipes[1])); diff --git a/ext/standard/tests/streams/proc_open_bug60120.phpt b/ext/standard/tests/streams/proc_open_bug60120.phpt index fc98913c4cc3f..95fa4e451412e 100644 --- a/ext/standard/tests/streams/proc_open_bug60120.phpt +++ b/ext/standard/tests/streams/proc_open_bug60120.phpt @@ -19,7 +19,7 @@ if (\$input) { TMPFILE ); -$command = sprintf("%s -n %s", getenv('TEST_PHP_EXECUTABLE_ESCAPED'), escapeshellarg($file)); +$command = [getenv('TEST_PHP_EXECUTABLE'), '-n', $file]; $process = proc_open( $command, diff --git a/ext/standard/tests/streams/proc_open_bug69900.phpt b/ext/standard/tests/streams/proc_open_bug69900.phpt index 323fc4a079cc6..576e93bc01fb6 100644 --- a/ext/standard/tests/streams/proc_open_bug69900.phpt +++ b/ext/standard/tests/streams/proc_open_bug69900.phpt @@ -25,7 +25,7 @@ file_put_contents($fl, $test_content); $descriptorspec = array(0 => array("pipe", "r"),1 => array("pipe", "w")); $pipes = array(); -$process = proc_open(getenv('TEST_PHP_EXECUTABLE_ESCAPED').' -n -f ' . escapeshellarg($fl), $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true)); +$process = proc_open([getenv('TEST_PHP_EXECUTABLE'), '-n', '-f', $fl], $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true)); $moreThanLimit = 0; for($i = 0; $i < 10; $i++){ diff --git a/ext/standard/tests/streams/stream_cast_loses_data.phpt b/ext/standard/tests/streams/stream_cast_loses_data.phpt index c2bcf9fd5914f..6a45ca4cac44a 100644 --- a/ext/standard/tests/streams/stream_cast_loses_data.phpt +++ b/ext/standard/tests/streams/stream_cast_loses_data.phpt @@ -21,7 +21,7 @@ fgets($stream); // cast $stream and read fd until eof. Print each line that was read, prefixed with "proc open stdin:" $process = proc_open( - 'sed "s/^/proc open stdin:/"', + ['sed', 's/^/proc open stdin:/'], [ 0 => $stream, 1 => ['pipe', 'w'], diff --git a/sapi/cli/tests/022.phpt b/sapi/cli/tests/022.phpt index 1afb5fc371a7a..bf38eeb869301 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-- STDERR, ); $pipes = array(); -$proc = proc_open("$php -n " . escapeshellarg($test_file), $desc, $pipes); +$proc = proc_open([$php, '-n', $test_file], $desc, $pipes); var_dump($proc); if (!$proc) { exit(1); diff --git a/sapi/cli/tests/023.phpt b/sapi/cli/tests/023.phpt index ae8ac5e8da3ba..3714b3ccf2344 100644 --- a/sapi/cli/tests/023.phpt +++ b/sapi/cli/tests/023.phpt @@ -7,10 +7,9 @@ if (substr(PHP_OS, 0, 3) == "WIN") die("skip non windows test"); ?> --FILE-- array("pipe", "w"), ); $pipes = array(); -$proc = proc_open("$php -c $ini_file_escaped -r 'echo ini_get(\"memory_limit\");'", $desc, $pipes); +$proc = proc_open([$php, '-c', $ini_file, '-r', 'echo ini_get("memory_limit");'], $desc, $pipes); if (!$proc) { exit(1); } diff --git a/sapi/cli/tests/sapi_windows_set_ctrl_handler.phpt b/sapi/cli/tests/sapi_windows_set_ctrl_handler.phpt index 3d93a82733464..ff8ce3566e935 100644 --- a/sapi/cli/tests/sapi_windows_set_ctrl_handler.phpt +++ b/sapi/cli/tests/sapi_windows_set_ctrl_handler.phpt @@ -24,7 +24,7 @@ if ($is_child) { while(1) usleep(100); } else { - $cmd = getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n " . $argv[0] . " 1"; + $cmd = [getenv('TEST_PHP_EXECUTABLE'), "-n", $argv[0] , "1"]; $spec = [0 => ["pipe", "r"], 1 => ["pipe", "w"]]; $proc = proc_open($cmd, $spec, $pipes, NULL, NULL, ["bypass_shell" => true, "create_process_group" => true]);