Fix null static_variable_ptr for uncalled fake closures

Closes GH-8083
Closes GH-8109
This commit is contained in:
Ilija Tovilo 2022-02-17 14:48:18 +01:00
parent afbb9b9a1b
commit 19063a84f0
No known key found for this signature in database
GPG Key ID: A4F5D403F118200A
3 changed files with 31 additions and 0 deletions

2
NEWS
View File

@ -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)

22
Zend/tests/gh8083.phpt Normal file
View File

@ -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
}
}

View File

@ -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 */