[php-src] Issue #11399: PHP incorrectly closes file handles when used to replace STDIN/STDOUT/STDERR
| From: | gnif | Date: | Thu, 08 Jun 2023 05:56:18 +0000 |
| Subject: | [php-src] Issue #11399: PHP incorrectly closes file handles when used to replace STDIN/STDOUT/STDERR | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244622@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11399
Author: gnif
### Description
The following code:
```php
<?php
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
fopen('/dev/null', 'r');
fopen('/dev/null', 'w');
fopen('/dev/null', 'w');
exec("dig +noall +answer -t ns -q 'www.google.com'", $out, $ret);
file_put_contents('ret.txt', $ret . "\n");
```
Resulted in exec failing with the return code 134 as seen in
ret.txt
PHP's garbage collection seems to have not taken into account that the file handles opened are
now in use as stdin/stdout/stderr. Obviously this can be worked around by storing the result of
fopen into some global vars, but IMO this is a bug.
### PHP Version
PHP 8.2.6
### Operating System
Debian 11