Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/standard/proc_open.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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