From 9c7f29a4cf189f2bed04c70c68ce3701b73348e2 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 17 Feb 2022 14:48:18 +0100 Subject: [PATCH] Fix null static_variable_ptr for uncalled fake closures Closes GH-8083 --- Zend/tests/gh8083.phpt | 22 ++++++++++++++++++++++ Zend/zend_closures.c | 7 +++++++ 2 files changed, 29 insertions(+) create mode 100644 Zend/tests/gh8083.phpt diff --git a/Zend/tests/gh8083.phpt b/Zend/tests/gh8083.phpt new file mode 100644 index 0000000000000..a98de47cbf375 --- /dev/null +++ b/Zend/tests/gh8083.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-8083 (var_dump() on closure with static variable segfaults) +--FILE-- + +--EXPECT-- +object(Closure)#1 (1) { + ["static"]=> + array(1) { + ["i"]=> + NULL + } +} diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index b5c0b47553248..0dab5537a3752 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -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 */