From 9bc02c17097075ba7a9b077e56d59f110db1110f Mon Sep 17 00:00:00 2001 From: datibbaw Date: Thu, 10 Oct 2013 14:35:11 +0800 Subject: [PATCH 1/4] Changed zpp argument for environment to 'a' instead of 'a!' --- ext/standard/proc_open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index d78ca9976b825..f46972350037c 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -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!aa!", &command, &command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment, &other_options) == FAILURE) { RETURN_FALSE; From 201507f34bb56d4a470b5aaebe0dd9a1daed0e0f Mon Sep 17 00:00:00 2001 From: datibbaw Date: Thu, 10 Oct 2013 18:17:02 +0800 Subject: [PATCH 2/4] Using `a/!` instead of `a` to avoid regression of #64770 --- ext/standard/proc_open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index f46972350037c..66d87aec9047e 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -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!aa!", &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; From 700e2ea2f7a1a15bfcf515b04ab79499789fe7ba Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Thu, 10 Oct 2013 20:21:14 +0800 Subject: [PATCH 3/4] Added a test case --- ext/standard/tests/streams/bug60602.phpt | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 ext/standard/tests/streams/bug60602.phpt diff --git a/ext/standard/tests/streams/bug60602.phpt b/ext/standard/tests/streams/bug60602.phpt new file mode 100644 index 0000000000000..59233b974a8ff --- /dev/null +++ b/ext/standard/tests/streams/bug60602.phpt @@ -0,0 +1,55 @@ +--TEST-- +Bug #60602 proc_open() modifies environment if it contains arrays +--FILE-- + 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 /Users/tjerk/work/php-src/ext/standard/tests/streams/bug60602.php on line 12 +int(%d) +int(0) +bool(true) +==DONE== From 857fc8d3b021a4fb1889a29c4b51d5197bed6b2a Mon Sep 17 00:00:00 2001 From: datibbaw Date: Fri, 11 Oct 2013 09:45:41 +0800 Subject: [PATCH 4/4] Make the test work on other machines too =S --- ext/standard/tests/streams/bug60602.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/tests/streams/bug60602.phpt b/ext/standard/tests/streams/bug60602.phpt index 59233b974a8ff..f0a3cf83e870c 100644 --- a/ext/standard/tests/streams/bug60602.phpt +++ b/ext/standard/tests/streams/bug60602.phpt @@ -48,7 +48,7 @@ if (is_resource($p)) { ?> ==DONE== --EXPECTF-- -Notice: Array to string conversion in /Users/tjerk/work/php-src/ext/standard/tests/streams/bug60602.php on line 12 +Notice: Array to string conversion in %s on line %d int(%d) int(0) bool(true)