Skip to content

Commit 330ffe2

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
2 parents 574f230 + c34f26a commit 330ffe2

File tree

2 files changed

+86
-8
lines changed

2 files changed

+86
-8
lines changed

ext/standard/proc_open.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,17 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
112112
zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS;
113113
zend_hash_move_forward_ex(target_hash, &pos)) {
114114

115-
convert_to_string_ex(element);
116-
el_len = Z_STRLEN_PP(element);
115+
if (Z_TYPE_PP(element) != IS_STRING) {
116+
zval tmp;
117+
118+
MAKE_COPY_ZVAL(element, &tmp);
119+
convert_to_string(&tmp);
120+
el_len = Z_STRLEN(tmp);
121+
122+
zval_dtor(&tmp);
123+
} else {
124+
el_len = Z_STRLEN_PP(element);
125+
}
117126
if (el_len == 0) {
118127
continue;
119128
}
@@ -125,7 +134,7 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
125134
if (string_length == 0) {
126135
continue;
127136
}
128-
sizeenv += string_length+1;
137+
sizeenv += string_length;
129138
break;
130139
}
131140
}
@@ -138,19 +147,26 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
138147
for (zend_hash_internal_pointer_reset_ex(target_hash, &pos);
139148
zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS;
140149
zend_hash_move_forward_ex(target_hash, &pos)) {
150+
zval tmp;
141151

142-
convert_to_string_ex(element);
143-
el_len = Z_STRLEN_PP(element);
152+
if (Z_TYPE_PP(element) != IS_STRING) {
153+
MAKE_COPY_ZVAL(element, &tmp);
154+
convert_to_string(&tmp);
155+
} else {
156+
tmp = **element;
157+
}
158+
159+
el_len = Z_STRLEN(tmp);
144160

145161
if (el_len == 0) {
146-
continue;
162+
goto next_element;
147163
}
148164

149-
data = Z_STRVAL_PP(element);
165+
data = Z_STRVAL(tmp);
150166
switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) {
151167
case HASH_KEY_IS_STRING:
152168
if (string_length == 0) {
153-
continue;
169+
goto next_element;
154170
}
155171

156172
l = string_length + el_len + 1;
@@ -175,6 +191,11 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
175191
case HASH_KEY_NON_EXISTENT:
176192
break;
177193
}
194+
195+
next_element:
196+
if (Z_TYPE_PP(element) != IS_STRING) {
197+
zval_dtor(&tmp);
198+
}
178199
}
179200

180201
assert((uint)(p - env.envp) <= sizeenv);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
Bug #60602 proc_open() modifies environment if it contains arrays
3+
--FILE--
4+
<?php
5+
6+
$descs = array(
7+
0 => array('pipe', 'r'), // stdin
8+
1 => array('pipe', 'w'), // stdout
9+
2 => array('pipe', 'w'), // strerr
10+
);
11+
12+
$environment = array('test' => array(1, 2, 3));
13+
14+
$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
15+
$p = proc_open($cmd, $descs, $pipes, '.', $environment);
16+
17+
if (is_resource($p)) {
18+
$data = '';
19+
20+
while (1) {
21+
$w = $e = NULL;
22+
$n = stream_select($pipes, $w, $e, 300);
23+
24+
if ($n === false) {
25+
echo "no streams \n";
26+
break;
27+
} else if ($n === 0) {
28+
echo "process timed out\n";
29+
proc_terminate($p, 9);
30+
break;
31+
} else if ($n > 0) {
32+
$line = fread($pipes[1], 8192);
33+
if (strlen($line) == 0) {
34+
/* EOF */
35+
break;
36+
}
37+
$data .= $line;
38+
}
39+
}
40+
var_dump(strlen($data));
41+
42+
$ret = proc_close($p);
43+
var_dump($ret);
44+
var_dump(is_array($environment['test']));
45+
} else {
46+
echo "no process\n";
47+
}
48+
?>
49+
==DONE==
50+
--EXPECTF--
51+
Notice: Array to string conversion in %s on line %d
52+
53+
Notice: Array to string conversion in %s on line %d
54+
int(%d)
55+
int(0)
56+
bool(true)
57+
==DONE==

0 commit comments

Comments
 (0)