Skip to content

Commit

Permalink
Fix GH-12655: proc_open() does not take into account references in th…
Browse files Browse the repository at this point in the history
…e descriptor array

Closes GH-12658.
  • Loading branch information
nielsdos authored and ramsey committed Nov 23, 2023
1 parent fe34dd1 commit c376f99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions ext/standard/proc_open.c
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions ext/standard/tests/general_functions/gh12655.phpt
@@ -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

0 comments on commit c376f99

Please sign in to comment.