Skip to content

Commit fee3863

Browse files
committed
Fix #78840: imploding $GLOBALS crashes
We add support for IS_INDIRECT zvals to implode().
1 parent 23c65a8 commit fee3863

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PHP NEWS
2222
- Standard:
2323
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
2424
. Fixed bug #77638 (var_export'ing certain class instances segfaults). (cmb)
25+
. Fixed bug #78840 (imploding $GLOBALS crashes). (cmb)
2526

2627
21 Nov 2019, PHP 7.3.12
2728

ext/standard/string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,14 +1216,14 @@ PHPAPI void php_implode(const zend_string *glue, zval *pieces, zval *return_valu
12161216
RETURN_EMPTY_STRING();
12171217
} else if (numelems == 1) {
12181218
/* loop to search the first not undefined element... */
1219-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pieces), tmp) {
1219+
ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(pieces), tmp) {
12201220
RETURN_STR(zval_get_string(tmp));
12211221
} ZEND_HASH_FOREACH_END();
12221222
}
12231223

12241224
ptr = strings = do_alloca((sizeof(*strings)) * numelems, use_heap);
12251225

1226-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pieces), tmp) {
1226+
ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(pieces), tmp) {
12271227
if (EXPECTED(Z_TYPE_P(tmp) == IS_STRING)) {
12281228
ptr->str = Z_STR_P(tmp);
12291229
len += ZSTR_LEN(ptr->str);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #78840 (imploding $GLOBALS crashes)
3+
--FILE--
4+
<?php
5+
$glue = '';
6+
@implode($glue, $GLOBALS);
7+
echo "done\n";
8+
?>
9+
--EXPECT--
10+
done

0 commit comments

Comments
 (0)