Skip to content

Commit dbc780b

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 704aadd commit dbc780b

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
@@ -3554,6 +3554,13 @@ 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);
35563556
ZEND_ASSERT(Z_TYPE_P(zval_ptr) != IS_REFERENCE);
3557+
3558+
/* clear reference before invoking the destructor, or
3559+
else something inside the destructor may assign the
3560+
reference again, triggering another recursive
3561+
destructor call */
3562+
ZVAL_UNDEF(zval_ptr);
3563+
35573564
if (!GC_DELREF(ref)) {
35583565
rc_dtor_func(ref);
35593566
} else if (UNEXPECTED(GC_MAY_LEAK(ref))) {

0 commit comments

Comments
 (0)