Handle non-INDIRECT symbol table entries in zend_fiber_object_gc() (#10386)

Fixes GH-10340
This commit is contained in:
Arnaud Le Blanc 2023-01-27 10:52:42 +01:00 committed by Sergey Panteleev
parent 1ceb2f3313
commit 36d55f8918
No known key found for this signature in database
GPG key ID: 659A97C9CF2A795A
4 changed files with 80 additions and 2 deletions

View file

@ -0,0 +1,19 @@
--TEST--
Bug GH-10340 001 (Assertion in zend_fiber_object_gc())
--FILE--
<?php
function f() {
$$y = Fiber::getCurrent();
Fiber::suspend();
}
$fiber = new Fiber(function() {
get_defined_vars();
f();
});
$fiber->start();
gc_collect_cycles();
?>
==DONE==
--EXPECTF--
Warning: Undefined variable $y in %s on line %d
==DONE==

View file

@ -0,0 +1,19 @@
--TEST--
Bug GH-10340 002 (Assertion in zend_fiber_object_gc())
--FILE--
<?php
function f() {
$y = 'a';
$$y = Fiber::getCurrent();
Fiber::suspend();
}
$fiber = new Fiber(function() {
get_defined_vars();
f();
});
$fiber->start();
gc_collect_cycles();
?>
==DONE==
--EXPECT--
==DONE==

View file

@ -0,0 +1,38 @@
--TEST--
Bug GH-10340 003 (Assertion in zend_fiber_object_gc())
--FILE--
<?php
class C {
public function __destruct() {
echo __METHOD__, "\n";
}
}
function f() {
$c = new C();
$y = 'a';
$$y = Fiber::getCurrent();
Fiber::suspend();
}
$fiber = new Fiber(function() {
get_defined_vars();
f();
});
$fiber->start();
print "1\n";
$fiber = null;
gc_collect_cycles();
print "2\n";
?>
==DONE==
--EXPECT--
1
C::__destruct
2
==DONE==

View file

@ -674,8 +674,10 @@ static HashTable *zend_fiber_object_gc(zend_object *object, zval **table, int *n
if (lastSymTable) {
zval *val;
ZEND_HASH_FOREACH_VAL(lastSymTable, val) {
ZEND_ASSERT(Z_TYPE_P(val) == IS_INDIRECT);
zend_get_gc_buffer_add_zval(buf, Z_INDIRECT_P(val));
if (EXPECTED(Z_TYPE_P(val) == IS_INDIRECT)) {
val = Z_INDIRECT_P(val);
}
zend_get_gc_buffer_add_zval(buf, val);
} ZEND_HASH_FOREACH_END();
}
lastSymTable = symTable;