Skip to content

Commit 75efa73

Browse files
committed
Do not use a shell in proc_open if not really needed
1 parent 406a2b4 commit 75efa73

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/Util/PHP/AbstractPhpProcess.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ public function runTestJob(string $job, Test $test, string $processResultFile):
156156

157157
/**
158158
* Returns the command based into the configurations.
159+
*
160+
* @return string[]
159161
*/
160-
public function getCommand(array $settings, ?string $file = null): string
162+
public function getCommand(array $settings, ?string $file = null): array
161163
{
162164
$runtime = new Runtime;
163165

164-
$command = $runtime->getBinary();
166+
$command = [];
167+
$command[] = $runtime->getRawBinary();
165168

166169
if ($runtime->hasPCOV()) {
167170
$settings = array_merge(
@@ -179,29 +182,29 @@ public function getCommand(array $settings, ?string $file = null): string
179182
);
180183
}
181184

182-
$command .= $this->settingsToParameters($settings);
185+
$command = array_merge($command, $this->settingsToParameters($settings));
183186

184187
if (PHP_SAPI === 'phpdbg') {
185-
$command .= ' -qrr';
188+
$command[] = '-qrr';
186189

187190
if (!$file) {
188-
$command .= 's=';
191+
$command[] = 's=';
189192
}
190193
}
191194

192195
if ($file) {
193-
$command .= ' ' . escapeshellarg($file);
196+
$command[] = $file;
194197
}
195198

196199
if ($this->arguments) {
197200
if (!$file) {
198-
$command .= ' --';
201+
$command[] = '--';
199202
}
200-
$command .= ' ' . $this->arguments;
203+
$command[] = $this->arguments;
201204
}
202205

203206
if ($this->stderrRedirection) {
204-
$command .= ' 2>&1';
207+
$command[] = '2>&1';
205208
}
206209

207210
return $command;
@@ -212,12 +215,17 @@ public function getCommand(array $settings, ?string $file = null): string
212215
*/
213216
abstract public function runJob(string $job, array $settings = []): array;
214217

215-
protected function settingsToParameters(array $settings): string
218+
/**
219+
* @param array $settings
220+
* @return list<string>
221+
*/
222+
protected function settingsToParameters(array $settings): array
216223
{
217-
$buffer = '';
224+
$buffer = [];
218225

219226
foreach ($settings as $setting) {
220-
$buffer .= ' -d ' . escapeshellarg($setting);
227+
$buffer[] = '-d';
228+
$buffer[] = $setting;
221229
}
222230

223231
return $buffer;

0 commit comments

Comments
 (0)