Skip to content

Commit ddb804d

Browse files
committed
Zend/zend_execute: clear reference before calling dtor
If we don't do this, then `zend_objects_store_del()` will call the PHP destructor, which may then recurse into `zend_objects_store_del()`, leading to a use-after-free / double-free bug. Fixes failures of `Zend/tests/gh10168_3.phpt` (added recently by 71ddede) which, depending on the timing, can trigger the recursive zend_objects_store_del() call. This is similar to commit a057f06
1 parent 8c8a38a commit ddb804d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Zend/zend_execute.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,13 @@ ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref,
35533553
static zend_always_inline void i_zval_ptr_dtor_noref(zval *zval_ptr) {
35543554
if (Z_REFCOUNTED_P(zval_ptr)) {
35553555
zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
3556+
3557+
/* clear reference before invoking the destructor, or
3558+
else something inside the destructor may assign the
3559+
reference again, triggering another recursive
3560+
destructor call */
3561+
ZVAL_UNDEF(zval_ptr);
3562+
35563563
ZEND_ASSERT(Z_TYPE_P(zval_ptr) != IS_REFERENCE);
35573564
if (!GC_DELREF(ref)) {
35583565
rc_dtor_func(ref);

0 commit comments

Comments
 (0)