From b765f96f5f6d7d5da77e1d57f80b98f1fde16cde Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 7 Jul 2020 10:11:34 +0200 Subject: [PATCH] Fixed bug #79778 In the interest of avoiding side-effects during dumping, I'm replacing the value with a string instead of performing an update constant operation. --- NEWS | 4 ++++ Zend/tests/bug79778.phpt | 26 ++++++++++++++++++++++++++ Zend/zend_closures.c | 7 +++++++ 3 files changed, 37 insertions(+) create mode 100644 Zend/tests/bug79778.phpt diff --git a/NEWS b/NEWS index 57b38992157..279ce98c617 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ PHP NEWS . Fixed bug #79030 (Upgrade apache2handler's php_apache_sapi_get_request_time to return usec). (Herbert256) +- Core: + . Fixed bug #79778 (Assertion failure if dumping closure with unresolved + static variable). (Nikita) + - COM: . Fixed bug #63208 (BSTR to PHP string conversion not binary safe). (cmb) diff --git a/Zend/tests/bug79778.phpt b/Zend/tests/bug79778.phpt new file mode 100644 index 00000000000..f1476a95cf8 --- /dev/null +++ b/Zend/tests/bug79778.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #79778: Assertion failure if dumping closure with unresolved static variable +--FILE-- + +--EXPECT-- +object(Closure)#1 (1) { + ["static"]=> + array(1) { + ["var"]=> + string(14) "" + } +} +Closure Object +( + [static] => Array + ( + [var] => + ) + +) diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 4261a748603..b9d8bd1c750 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -506,9 +506,16 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp) /* {{{ debug_info = zend_new_array(8); if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) { + zval *var; HashTable *static_variables = closure->func.op_array.static_variables; ZVAL_ARR(&val, zend_array_dup(static_variables)); zend_hash_update(debug_info, ZSTR_KNOWN(ZEND_STR_STATIC), &val); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL(val), var) { + if (Z_TYPE_P(var) == IS_CONSTANT_AST) { + zval_ptr_dtor(var); + ZVAL_STRING(var, ""); + } + } ZEND_HASH_FOREACH_END(); } if (Z_TYPE(closure->this_ptr) != IS_UNDEF) {