Skip to content

Commit ca5fbcf

Browse files
committed
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.
1 parent 530e0d6 commit ca5fbcf

23 files changed

+58
-40
lines changed

ext/curl/tests/curl_setopt_ssl.phpt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,22 @@ if ($serverCert === false
6161
$port = 14430;
6262

6363
// set up local server
64-
$cmd = "openssl s_server -key $serverKeyPath -cert $serverCertPath -accept $port -www -CAfile $clientCertPath -verify_return_error -Verify 1";
64+
$cmd = [
65+
'openssl',
66+
's_server',
67+
'-key',
68+
$serverKeyPath,
69+
'-cert',
70+
$serverCertPath,
71+
'-accept',
72+
$port,
73+
'-www',
74+
'-CAfile',
75+
$clientCertPath,
76+
'-verify_return_error',
77+
'-Verify',
78+
1
79+
];
6580
$process = proc_open($cmd, [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
6681

6782
if ($process === false) {

ext/openssl/tests/stream_server_reneg_limit.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ $serverCode = sprintf($serverCode, $certFile);
7373
$clientCode = <<<'CODE'
7474
phpt_wait();
7575
76-
$cmd = 'openssl s_client -connect 127.0.0.1:64321';
76+
$cmd = [
77+
'openssl',
78+
's_client',
79+
'-connect',
80+
'127.0.0.1:64321'
81+
];
7782
$descriptorSpec = [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]];
7883
$process = proc_open($cmd, $descriptorSpec, $pipes);
7984

ext/pcntl/tests/waiting_on_sigchild_pcntl_wait.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pcntl_signal(SIGCHLD, function($sig, $info) use (&$processes) {
2222

2323
for ($i = 0; $i <= 5; $i++) {
2424
// Sleeping ensures we get to add the process to the list before the signal is invoked.
25-
$process = proc_open('sleep 1', [], $pipes);
25+
$process = proc_open(['sleep', '1'], [], $pipes);
2626
$pid = proc_get_status($process)['pid'];
2727
$processes[$pid] = $process;
2828
}

ext/standard/tests/file/proc_open01.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ proc_open() regression test 1 (proc_open() leak)
44
<?php
55
$pipes = array(1, 2, 3);
66
$orig_pipes = $pipes;
7-
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
7+
$php = getenv('TEST_PHP_EXECUTABLE');
88
if ($php === false) {
99
die("no php executable defined");
1010
}
1111
$proc = proc_open(
12-
"$php -n",
12+
[$php, '-n'],
1313
array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')),
1414
$pipes, getcwd(), array(), array()
1515
);

ext/standard/tests/general_functions/bug34794.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ if (!is_executable('/bin/cat')) echo 'skip cat not found';
77
--FILE--
88
<?php
99
echo "Opening process 1\n";
10-
$process1 = proc_open('/bin/cat', array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes1);
10+
$process1 = proc_open(['/bin/cat'], array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes1);
1111

1212
echo "Opening process 2\n";
13-
$process2 = proc_open('/bin/cat', array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes2);
13+
$process2 = proc_open(['/bin/cat'], array(0 => array('pipe', 'r'), 1 =>array('pipe', 'r')), $pipes2);
1414

1515

1616
echo "Closing process 1\n";

ext/standard/tests/general_functions/bug44667.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $descriptor_spec = array(
1212
1 => array('pipe', 'wb'),
1313
);
1414

15-
$proc = proc_open('cat', $descriptor_spec, $pipes);
15+
$proc = proc_open(['cat'], $descriptor_spec, $pipes);
1616

1717
fwrite($pipes[0], 'Hello', 5);
1818
fflush($pipes[0]);

ext/standard/tests/general_functions/gh10239_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
77
?>
88
--FILE--
99
<?php
10-
$p = proc_open('sleep 1', array(), $foo);
10+
$p = proc_open(['sleep', '1'], array(), $foo);
1111
do {
1212
usleep(100000);
1313
$s = proc_get_status($p);

ext/standard/tests/general_functions/gh10239_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
77
?>
88
--FILE--
99
<?php
10-
$p = proc_open('false', array(), $foo);
10+
$p = proc_open(['false'], array(), $foo);
1111
usleep(2 * 1000 * 1000);
1212
var_dump(proc_get_status($p));
1313
var_dump(proc_get_status($p));

ext/standard/tests/general_functions/gh12655.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ foreach ( $descriptor_spec as $fd => &$d )
1414
// don't do anything, just the fact that we used "&$d" will sink the ship!
1515
}
1616

17-
$proc = proc_open(PHP_BINARY, $descriptor_spec, $pipes);
17+
$proc = proc_open([PHP_BINARY], $descriptor_spec, $pipes);
1818
echo $proc === false ? "FAILED\n" : "SUCCEEDED\n";
1919

2020
?>

ext/standard/tests/general_functions/proc_open.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ds = array(
1414
);
1515

1616
$cat = proc_open(
17-
"/bin/cat",
17+
['/bin/cat'],
1818
$ds,
1919
$pipes
2020
);

ext/standard/tests/general_functions/proc_open_pipes1.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ for ($i = 3; $i<= 30; $i++) {
77
$spec[$i] = array('pipe', 'w');
88
}
99

10-
$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED");
11-
$callee = escapeshellarg(__DIR__ . "/proc_open_pipes_sleep.inc");
12-
proc_open("$php -n $callee", $spec, $pipes);
10+
$php = getenv("TEST_PHP_EXECUTABLE");
11+
$callee = __DIR__ . "/proc_open_pipes_sleep.inc";
12+
proc_open([$php, '-n', $callee], $spec, $pipes);
1313

1414
var_dump(count($spec));
1515
var_dump($pipes);

ext/standard/tests/general_functions/proc_open_pipes2.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ proc_open() with no pipes
55

66
$spec = array();
77

8-
$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED");
9-
$callee = escapeshellarg(__DIR__ . "/proc_open_pipes_sleep.inc");
10-
proc_open("$php -n $callee", $spec, $pipes);
8+
$php = getenv("TEST_PHP_EXECUTABLE");
9+
$callee = __DIR__ . "/proc_open_pipes_sleep.inc";
10+
proc_open([$php, "-n", $callee], $spec, $pipes);
1111

1212
var_dump(count($spec));
1313
var_dump($pipes);

ext/standard/tests/general_functions/proc_open_pipes3.phpt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@ for ($i = 3; $i<= 5; $i++) {
77
$spec[$i] = array('pipe', 'w');
88
}
99

10-
$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED");
10+
$php = getenv("TEST_PHP_EXECUTABLE");
1111
$callee = __DIR__ . "/proc_open_pipes_sleep.inc";
12-
$callee_escaped = escapeshellarg($callee);
1312

1413
$spec[$i] = array('pi');
15-
proc_open("$php -n $callee_escaped", $spec, $pipes);
14+
proc_open([$php, "-n", $callee], $spec, $pipes);
1615

1716
$spec[$i] = 1;
1817
try {
19-
proc_open("$php -n $callee_escaped", $spec, $pipes);
18+
proc_open([$php, "-n", $callee], $spec, $pipes);
2019
} catch (ValueError $exception) {
2120
echo $exception->getMessage() . "\n";
2221
}
2322

2423
$spec[$i] = array('pipe', "test");
25-
proc_open("$php -n $callee_escaped", $spec, $pipes);
24+
proc_open([$php, "-n", $callee], $spec, $pipes);
2625
var_dump($pipes);
2726

2827
$spec[$i] = array('file', "test", "z");
29-
proc_open("$php -n $callee_escaped", $spec, $pipes);
28+
proc_open([$php, "-n", $callee], $spec, $pipes);
3029
var_dump($pipes);
3130

3231
echo "END\n";

ext/standard/tests/streams/bug46024.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Bug #46024 stream_select() doesn't return the correct number
33
--SKIPIF--
44
<?php
5-
if (!getenv('TEST_PHP_EXECUTABLE_ESCAPED')) die("skip TEST_PHP_EXECUTABLE_ESCAPED not defined");
5+
if (!getenv('TEST_PHP_EXECUTABLE')) die("skip TEST_PHP_EXECUTABLE not defined");
66
// Terminating the process may cause a bailout while writing out the phpinfo,
77
// which may leak a temporary hash table. This does not seems worth fixing.
88
if (getenv('SKIP_ASAN')) die("xleak Test may leak");
@@ -11,9 +11,9 @@ if (getenv('SKIP_ASAN')) die("xleak Test may leak");
1111
<?php
1212
$pipes = array();
1313
$proc = proc_open(
14-
getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n -i"
15-
,array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'))
16-
,$pipes, __DIR__, array(), array()
14+
[getenv('TEST_PHP_EXECUTABLE'), '-n', '-i'],
15+
array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')),
16+
$pipes, __DIR__, array(), array()
1717
);
1818
var_dump($proc);
1919
if (!$proc) {

ext/standard/tests/streams/bug60602.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $descs = array(
1111

1212
$environment = array('test' => array(1, 2, 3));
1313

14-
$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
14+
$cmd = [(substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls'];
1515
$p = proc_open($cmd, $descs, $pipes, '.', $environment);
1616

1717
if (is_resource($p)) {

ext/standard/tests/streams/bug70198.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if (!\$socket) {
3636
SRV;
3737
file_put_contents($srv_fl, $srv_fl_cont);
3838
$dummy0 = $dummy1 = array();
39-
$srv_proc = proc_open(getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n $srv_fl_escaped", $dummy0, $dummy1);
39+
$srv_proc = proc_open([getenv('TEST_PHP_EXECUTABLE'), "-n", $srv_fl], $dummy0, $dummy1);
4040

4141
$i = 0;
4242
/* wait a bit for the server startup */

ext/standard/tests/streams/bug72853.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $descs = array(
1414
1 => array('pipe', 'w'), // stdout
1515
);
1616

17-
$p = proc_open("ls", $descs, $pipes, '.', NULL, NULL);
17+
$p = proc_open(['ls'], $descs, $pipes, '.', NULL, NULL);
1818

1919
stream_set_blocking($pipes[1], false);
2020
var_dump(stream_get_meta_data($pipes[1]));

ext/standard/tests/streams/proc_open_bug60120.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (\$input) {
1919
TMPFILE
2020
);
2121

22-
$command = sprintf("%s -n %s", getenv('TEST_PHP_EXECUTABLE_ESCAPED'), escapeshellarg($file));
22+
$command = [getenv('TEST_PHP_EXECUTABLE'), '-n', $file];
2323

2424
$process = proc_open(
2525
$command,

ext/standard/tests/streams/proc_open_bug69900.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ file_put_contents($fl, $test_content);
2525
$descriptorspec = array(0 => array("pipe", "r"),1 => array("pipe", "w"));
2626
$pipes = array();
2727

28-
$process = proc_open(getenv('TEST_PHP_EXECUTABLE_ESCAPED').' -n -f ' . escapeshellarg($fl), $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true));
28+
$process = proc_open([getenv('TEST_PHP_EXECUTABLE'), '-n', '-f', $fl], $descriptorspec, $pipes, NULL, NULL, array("blocking_pipes" => true));
2929

3030
$moreThanLimit = 0;
3131
for($i = 0; $i < 10; $i++){

ext/standard/tests/streams/stream_cast_loses_data.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fgets($stream);
2121

2222
// cast $stream and read fd until eof. Print each line that was read, prefixed with "proc open stdin:"
2323
$process = proc_open(
24-
'sed "s/^/proc open stdin:/"',
24+
['sed', 's/^/proc open stdin:/'],
2525
[
2626
0 => $stream,
2727
1 => ['pipe', 'w'],

sapi/cli/tests/022.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (substr(PHP_OS, 0, 3) == "WIN") die("skip non windows test");
77
?>
88
--FILE--
99
<?php
10-
$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED");
10+
$php = getenv("TEST_PHP_EXECUTABLE");
1111
$socket_file = tempnam(sys_get_temp_dir(), pathinfo(__FILE__, PATHINFO_FILENAME) . '.sock');
1212
$test_file = __DIR__ . '/' . pathinfo(__FILE__, PATHINFO_FILENAME) . '.inc';
1313
if (file_exists($socket_file)) {
@@ -24,7 +24,7 @@ $desc = array(
2424
2 => STDERR,
2525
);
2626
$pipes = array();
27-
$proc = proc_open("$php -n " . escapeshellarg($test_file), $desc, $pipes);
27+
$proc = proc_open([$php, '-n', $test_file], $desc, $pipes);
2828
var_dump($proc);
2929
if (!$proc) {
3030
exit(1);

sapi/cli/tests/023.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ if (substr(PHP_OS, 0, 3) == "WIN") die("skip non windows test");
77
?>
88
--FILE--
99
<?php
10-
$php = getenv("TEST_PHP_EXECUTABLE_ESCAPED");
10+
$php = getenv("TEST_PHP_EXECUTABLE");
1111
$cwd = getcwd();
1212
$ini_file = __DIR__ . "/023.ini";
13-
$ini_file_escaped = escapeshellarg($ini_file);
1413
file_put_contents($ini_file, <<<INI
1514
; no sections should match as cli doesn't support any
1615
memory_limit = 40M
@@ -28,7 +27,7 @@ $desc = array(
2827
2 => array("pipe", "w"),
2928
);
3029
$pipes = array();
31-
$proc = proc_open("$php -c $ini_file_escaped -r 'echo ini_get(\"memory_limit\");'", $desc, $pipes);
30+
$proc = proc_open([$php, '-c', $ini_file, '-r', 'echo ini_get("memory_limit");'], $desc, $pipes);
3231
if (!$proc) {
3332
exit(1);
3433
}

sapi/cli/tests/sapi_windows_set_ctrl_handler.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if ($is_child) {
2424

2525
while(1) usleep(100);
2626
} else {
27-
$cmd = getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n " . $argv[0] . " 1";
27+
$cmd = [getenv('TEST_PHP_EXECUTABLE'), "-n", $argv[0] , "1"];
2828
$spec = [0 => ["pipe", "r"], 1 => ["pipe", "w"]];
2929

3030
$proc = proc_open($cmd, $spec, $pipes, NULL, NULL, ["bypass_shell" => true, "create_process_group" => true]);

0 commit comments

Comments
 (0)