Fix GH-12655: proc_open() does not take into account references in the descriptor array

Closes GH-12658.
This commit is contained in:
Niels Dossche 2023-11-12 18:43:35 +01:00
parent db26aee801
commit 86c7d3ed1f
3 changed files with 25 additions and 0 deletions

2
NEWS
View File

@ -12,6 +12,8 @@ PHP NEWS
. Fix memory leak in syslog device handling. (danog)
. Fixed bug GH-12621 (browscap segmentation fault when configured in the
vhost). (nielsdos)
. Fixed bug GH-12655 (proc_open() does not take into account references
in the descriptor array). (nielsdos)
- SQLite3:
. Fixed bug GH-12633 (sqlite3_defensive.phpt fails with sqlite 3.44.0).

View File

@ -1096,6 +1096,7 @@ PHP_FUNCTION(proc_open)
descriptors[ndesc].index = (int)nindex;
ZVAL_DEREF(descitem);
if (Z_TYPE_P(descitem) == IS_RESOURCE) {
if (set_proc_descriptor_from_resource(descitem, &descriptors[ndesc], ndesc) == FAILURE) {
goto exit_fail;

View File

@ -0,0 +1,22 @@
--TEST--
GH-12655 (proc_open(): Argument #2 ($descriptor_spec) must only contain arrays and streams [Descriptor item must be either an array or a File-Handle])
--FILE--
<?php
$descriptor_spec = [
0 => [ "pipe", "r" ], // stdin is a pipe that the child will read from
1 => [ "pipe", "w" ], // stdout is a pipe that the child will write to
2 => [ "pipe", "w" ], // stderr is a file to write to
];
foreach ( $descriptor_spec as $fd => &$d )
{
// don't do anything, just the fact that we used "&$d" will sink the ship!
}
$proc = proc_open(PHP_BINARY, $descriptor_spec, $pipes);
echo $proc === false ? "FAILED\n" : "SUCCEEDED\n";
?>
--EXPECT--
SUCCEEDED