Skip to content

Commit

Permalink
bug #19428 [Process] Fix write access check for pipes on Windows (nic…
Browse files Browse the repository at this point in the history
…olas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Process] Fix write access check for pipes on Windows

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19336, #19416
| License       | MIT
| Doc PR        | -

Commits
-------

66e694e [Process] Fix write access check for pipes on Windows
  • Loading branch information
nicolas-grekas committed Jul 28, 2016
2 parents 76dbd3c + 66e694e commit f9ba34f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Symfony/Component/Process/Pipes/WindowsPipes.php
Expand Up @@ -52,27 +52,30 @@ public function __construct($disableOutput, $input)
Process::STDERR => Process::ERR,
);
$tmpDir = sys_get_temp_dir();
if (!@fopen($file = $tmpDir.'\\sf_proc_00.check', 'wb')) {
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
}
@unlink($file);
$error = 'unknown reason';
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
for ($i = 0;; ++$i) {
foreach ($pipes as $pipe => $name) {
$file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
if (file_exists($file) && !@unlink($file)) {
if (file_exists($file) && !unlink($file)) {
continue 2;
}
$h = @fopen($file, 'xb');
$h = fopen($file, 'xb');
if (!$h && false === strpos($error, 'File exists')) {
restore_error_handler();
throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s', $error));
}
if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
continue 2;
}
if (isset($this->files[$pipe])) {
@unlink($this->files[$pipe]);
unlink($this->files[$pipe]);
}
$this->files[$pipe] = $file;
}
break;
}
restore_error_handler();
}

parent::__construct($input);
Expand Down

0 comments on commit f9ba34f

Please sign in to comment.