Skip to content

Commit 19063a8

Browse files
committed
Fix null static_variable_ptr for uncalled fake closures
Closes GH-8083 Closes GH-8109
1 parent afbb9b9 commit 19063a8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed Haiku ZTS build. (David Carlier)
77
. Fixed bug GH-8059 arginfo not regenerated for extension. (Remi)
8+
. Fixed bug GH-8083 Segfault when dumping uncalled fake closure with static
9+
variables. (ilutov)
810

911
- GD:
1012
. Fixed libpng warning when loading interlaced images. (Brett)

Zend/tests/gh8083.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-8083 (var_dump() on closure with static variable segfaults)
3+
--FILE--
4+
<?php
5+
6+
function func() {
7+
static $i;
8+
}
9+
10+
$x = func(...);
11+
12+
var_dump($x);
13+
14+
?>
15+
--EXPECT--
16+
object(Closure)#1 (1) {
17+
["static"]=>
18+
array(1) {
19+
["i"]=>
20+
NULL
21+
}
22+
}

Zend/zend_closures.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,13 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en
697697
}
698698
ZEND_MAP_PTR_INIT(closure->func.op_array.static_variables_ptr,
699699
&closure->func.op_array.static_variables);
700+
} else if (func->op_array.static_variables) {
701+
HashTable *ht = ZEND_MAP_PTR_GET(func->op_array.static_variables_ptr);
702+
703+
if (!ht) {
704+
ht = zend_array_dup(func->op_array.static_variables);
705+
ZEND_MAP_PTR_SET(closure->func.op_array.static_variables_ptr, ht);
706+
}
700707
}
701708

702709
/* Runtime cache is scope-dependent, so we cannot reuse it if the scope changed */

0 commit comments

Comments
 (0)