Skip to content
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

Changed proc_open() zpp argument to separate the environment array #487

Closed
wants to merge 4 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/standard/proc_open.c
Expand Up @@ -471,7 +471,7 @@ PHP_FUNCTION(proc_open)
php_file_descriptor_t slave_pty = -1;
#endif

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz|s!a!a!", &command,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz|s!a/!a!", &command,
&command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment,
&other_options) == FAILURE) {
RETURN_FALSE;
Expand Down
55 changes: 55 additions & 0 deletions ext/standard/tests/streams/bug60602.phpt
@@ -0,0 +1,55 @@
--TEST--
Bug #60602 proc_open() modifies environment if it contains arrays
--FILE--
<?php

$descs = array(
0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w'), // strerr
);

$environment = array('test' => array(1, 2, 3));

$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
$p = proc_open($cmd, $descs, $pipes, '.', $environment);

if (is_resource($p)) {
$data = '';

while (1) {
$w = $e = NULL;
$n = stream_select($pipes, $w, $e, 300);

if ($n === false) {
echo "no streams \n";
break;
} else if ($n === 0) {
echo "process timed out\n";
proc_terminate($p, 9);
break;
} else if ($n > 0) {
$line = fread($pipes[1], 8192);
if (strlen($line) == 0) {
/* EOF */
break;
}
$data .= $line;
}
}
var_dump(strlen($data));

$ret = proc_close($p);
var_dump($ret);
var_dump(is_array($environment['test']));
} else {
echo "no process\n";
}
?>
==DONE==
--EXPECTF--
Notice: Array to string conversion in %s on line %d
int(%d)
int(0)
bool(true)
==DONE==