Skip to content

Commit

Permalink
Fix null static_variable_ptr for uncalled fake closures
Browse files Browse the repository at this point in the history
Closes GH-8083
Closes GH-8109
  • Loading branch information
iluuu1994 committed Feb 19, 2022
1 parent afbb9b9 commit 19063a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed Haiku ZTS build. (David Carlier)
. Fixed bug GH-8059 arginfo not regenerated for extension. (Remi)
. Fixed bug GH-8083 Segfault when dumping uncalled fake closure with static
variables. (ilutov)

- GD:
. Fixed libpng warning when loading interlaced images. (Brett)
Expand Down
22 changes: 22 additions & 0 deletions Zend/tests/gh8083.phpt
@@ -0,0 +1,22 @@
--TEST--
GH-8083 (var_dump() on closure with static variable segfaults)
--FILE--
<?php

function func() {
static $i;
}

$x = func(...);

var_dump($x);

?>
--EXPECT--
object(Closure)#1 (1) {
["static"]=>
array(1) {
["i"]=>
NULL
}
}
7 changes: 7 additions & 0 deletions Zend/zend_closures.c
Expand Up @@ -697,6 +697,13 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en
}
ZEND_MAP_PTR_INIT(closure->func.op_array.static_variables_ptr,
&closure->func.op_array.static_variables);
} else if (func->op_array.static_variables) {
HashTable *ht = ZEND_MAP_PTR_GET(func->op_array.static_variables_ptr);

if (!ht) {
ht = zend_array_dup(func->op_array.static_variables);
ZEND_MAP_PTR_SET(closure->func.op_array.static_variables_ptr, ht);
}
}

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

0 comments on commit 19063a8

Please sign in to comment.