Skip to content

Commit 95aa236

Browse files
weaverryanfabpot
authored andcommitted
[Process] Fix bug where $this->callback is never null, resulting in bad argument
1 parent 62e115f commit 95aa236

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function start(callable $callback = null, array $env = [])
304304
$this->resetProcessData();
305305
$this->starttime = $this->lastOutputTime = microtime(true);
306306
$this->callback = $this->buildCallback($callback);
307-
$descriptors = $this->getDescriptors();
307+
$descriptors = $this->getDescriptors(null !== $callback);
308308

309309
if ($this->env) {
310310
$env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->env, $env, 'strcasecmp') : $this->env;
@@ -1240,15 +1240,15 @@ public static function isPtySupported(): bool
12401240
/**
12411241
* Creates the descriptors needed by the proc_open.
12421242
*/
1243-
private function getDescriptors(): array
1243+
private function getDescriptors(bool $hasCallback): array
12441244
{
12451245
if ($this->input instanceof \Iterator) {
12461246
$this->input->rewind();
12471247
}
12481248
if ('\\' === \DIRECTORY_SEPARATOR) {
1249-
$this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->callback);
1249+
$this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $hasCallback);
12501250
} else {
1251-
$this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->callback);
1251+
$this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $hasCallback);
12521252
}
12531253

12541254
return $this->processPipes->getDescriptors();

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ public function testCallbacksAreExecutedWithStart()
200200
$this->assertSame('foo'.\PHP_EOL, $data);
201201
}
202202

203+
public function testReadSupportIsDisabledWithoutCallback()
204+
{
205+
$this->expectException(LogicException::class);
206+
$this->expectExceptionMessage('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait".');
207+
208+
$process = $this->getProcess('echo foo');
209+
// disabling output + not passing a callback to start() => read support disabled
210+
$process->disableOutput();
211+
$process->start();
212+
$process->wait(function ($type, $buffer) use (&$data) {
213+
$data .= $buffer;
214+
});
215+
}
216+
203217
/**
204218
* tests results from sub processes.
205219
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy