1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
--TEST--
Using proc_open() with a command array (no shell)
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE');
$ds = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
echo "Empty command array:\n";
try {
proc_open([], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
echo "\nNul byte in program name:\n";
try {
proc_open(["php\0oops"], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
echo "\nNul byte in argument:\n";
try {
proc_open(["php", "arg\0oops"], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
echo "\nBasic usage:\n";
$proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes);
fpassthru($pipes[1]);
proc_close($proc);
putenv('ENV_1=ENV_1');
$env = ['ENV_2' => 'ENV_2'];
$cmd = [$php, '-n', '-r', 'var_dump(getenv("ENV_1"), getenv("ENV_2"));'];
echo "\nEnvironment inheritance:\n";
$proc = proc_open($cmd, $ds, $pipes);
fpassthru($pipes[1]);
proc_close($proc);
echo "\nExplicit environment:\n";
$proc = proc_open($cmd, $ds, $pipes, null, $env);
fpassthru($pipes[1]);
proc_close($proc);
echo "\nCheck that arguments are correctly passed through:\n";
$args = [
"Simple",
"White space\ttab\nnewline",
'"Quoted"',
'Qu"ot"ed',
'\\Back\\slash\\',
'\\\\Back\\\\slash\\\\',
'\\"Qu\\"ot\\"ed\\"',
];
$cmd = [$php, '-r', 'var_export(array_slice($argv, 1));', '--', ...$args];
$proc = proc_open($cmd, $ds, $pipes);
fpassthru($pipes[1]);
proc_close($proc);
?>
--EXPECT--
Empty command array:
Command array must have at least one element
Nul byte in program name:
Command array element 1 contains a null byte
Nul byte in argument:
Command array element 2 contains a null byte
Basic usage:
Hello World!
Environment inheritance:
string(5) "ENV_1"
bool(false)
Explicit environment:
bool(false)
string(5) "ENV_2"
Check that arguments are correctly passed through:
array (
0 => 'Simple',
1 => 'White space tab
newline',
2 => '"Quoted"',
3 => 'Qu"ot"ed',
4 => '\\Back\\slash\\',
5 => '\\\\Back\\\\slash\\\\',
6 => '\\"Qu\\"ot\\"ed\\"',
)
|