Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21383da

Browse files
[Process] Fix ignoring of bad env var names
1 parent346eacd commit21383da

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

‎src/Symfony/Component/Process/Process.php‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,24 +266,25 @@ public function start(callable $callback = null)
266266
$this->callback =$this->buildCallback($callback);
267267
$this->hasCallback =null !==$callback;
268268
$descriptors =$this->getDescriptors();
269+
$inheritEnv =$this->inheritEnv;
269270

270271
$commandline =$this->commandline;
271-
$envline ='';
272272

273-
if (null !==$this->env &&$this->inheritEnv) {
273+
$env =$this->env;
274+
$envBackup =array();
275+
if (null !==$env &&$inheritEnv) {
274276
if ('\\' ===DIRECTORY_SEPARATOR && !empty($this->options['bypass_shell']) && !$this->enhanceWindowsCompatibility) {
275277
thrownewLogicException('The "bypass_shell" option must be false to inherit environment variables while enhanced Windows compatibility is off');
276278
}
277-
$env ='\\' ===DIRECTORY_SEPARATOR ?'(SET %s)&&' :'export %s;';
278-
foreach ($this->envas$k =>$v) {
279-
$envline .=sprintf($env, ProcessUtils::escapeArgument("$k=$v"));
279+
280+
foreach ($envas$k =>$v) {
281+
$envBackup[$k] =getenv($v);
282+
putenv(false ===$v ||null ===$v ?$k :"$k=$v");
280283
}
281284
$env =null;
282-
}else {
283-
$env =$this->env;
284285
}
285286
if ('\\' ===DIRECTORY_SEPARATOR &&$this->enhanceWindowsCompatibility) {
286-
$commandline ='cmd /V:ON /E:ON /D /C "('.$envline.$commandline.')';
287+
$commandline ='cmd /V:ON /E:ON /D /C "('.$commandline.')';
287288
foreach ($this->processPipes->getFiles()as$offset =>$filename) {
288289
$commandline .=''.$offset.'>'.ProcessUtils::escapeArgument($filename);
289290
}
@@ -297,18 +298,20 @@ public function start(callable $callback = null)
297298
$descriptors[3] =array('pipe','w');
298299

299300
// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
300-
$commandline =$envline.'{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
301+
$commandline ='{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
301302
$commandline .='pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';
302303

303304
// Workaround for the bug, when PTS functionality is enabled.
304305
// @see : https://bugs.php.net/69442
305306
$ptsWorkaround =fopen(__FILE__,'r');
306-
}elseif ('' !==$envline) {
307-
$commandline =$envline.$commandline;
308307
}
309308

310309
$this->process =proc_open($commandline,$descriptors,$this->processPipes->pipes,$this->cwd,$env,$this->options);
311310

311+
foreach ($envBackupas$k =>$v) {
312+
putenv(false ===$v ?$k :"$k=$v");
313+
}
314+
312315
if (!is_resource($this->process)) {
313316
thrownewRuntimeException('Unable to launch a new process.');
314317
}
@@ -1099,15 +1102,7 @@ public function getEnv()
10991102
*/
11001103
publicfunctionsetEnv(array$env)
11011104
{
1102-
// Process can not handle env values that are arrays
1103-
$env =array_filter($env,function ($value) {
1104-
return !is_array($value);
1105-
});
1106-
1107-
$this->env =array();
1108-
foreach ($envas$key =>$value) {
1109-
$this->env[$key] = (string)$value;
1110-
}
1105+
$this->env =$env;
11111106

11121107
return$this;
11131108
}

‎src/Symfony/Component/Process/Tests/ProcessTest.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,18 @@ public function testChainedProcesses()
13911391
$this->assertSame('456',$p2->getOutput());
13921392
}
13931393

1394+
publicfunctiontestSetBadEnv()
1395+
{
1396+
$process =$this->getProcess('echo hello');
1397+
$process->setEnv(array('bad%%' =>'123'));
1398+
$process->inheritEnvironmentVariables(true);
1399+
1400+
$process->run();
1401+
1402+
$this->assertSame('hello'.PHP_EOL,$process->getOutput());
1403+
$this->assertSame('',$process->getErrorOutput());
1404+
}
1405+
13941406
publicfunctiontestInheritEnvEnabled()
13951407
{
13961408
$process =$this->getProcess(self::$phpBin.' -r'.escapeshellarg('echo serialize($_SERVER);'),null,array('BAR' =>'BAZ'));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp