[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Thu, 29 Oct 2026 18:19:31 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142956@lists.php.net to get a copy of this message
Author: David Carlier (devnexen) Date: 2026-10-29T18:17:22Z Commit: https://github.com/php/php-src/commit/7ab1c1a1b4e7d8e8a4c868969ee46ab526957348 Raw diff: https://github.com/php/php-src/commit/7ab1c1a1b4e7d8e8a4c868969ee46ab526957348.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: Fix GH-24989: Use-after-free in GC when an exception is thrown. Changed paths: A Zend/tests/gh24989.phpt A Zend/tests/gh24989_uncaught.phpt M Zend/zend_execute.c Diff: diff --git a/Zend/tests/gh24989.phpt b/Zend/tests/gh24989.phpt new file mode 100644 index 000000000000..02b12b3e70ae --- /dev/null +++ b/Zend/tests/gh24989.phpt @@ -0,0 +1,29 @@ +--TEST-- +GH-24989 (Use-after-free in GC when an exception is thrown) +--CREDITS-- +vi3tL0u1s +--FILE-- +<?php +class D { function __destruct() { gc_collect_cycles(); } } + +function loop_var() { + foreach (range(1, 2) as $v) { + $x = [new D, throw new Exception('loop')]; + } +} + +function tmp_var() { + $x = [range(1, 2), [new D, throw new Exception('tmp')]]; +} + +foreach (['loop_var', 'tmp_var'] as $f) { + try { + $f(); + } catch (Exception $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; + } +} +?> +--EXPECT-- +Exception: loop +Exception: tmp diff --git a/Zend/tests/gh24989_uncaught.phpt b/Zend/tests/gh24989_uncaught.phpt new file mode 100644 index 000000000000..5d3d317e806e --- /dev/null +++ b/Zend/tests/gh24989_uncaught.phpt @@ -0,0 +1,16 @@ +--TEST-- +GH-24989 (Use-after-free in GC when an exception is thrown, uncaught) +--CREDITS-- +vi3tL0u1s +--FILE-- +<?php +class D { function __destruct() { gc_collect_cycles(); } } +foreach (range(1, 2) as $v) { + $x = [new D, throw new Exception]; +} +?> +--EXPECTF-- +Fatal error: Uncaught Exception in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 4e82fa207594..bac0095d1c43 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -4988,7 +4988,10 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, } if (kind == ZEND_LIVE_TMPVAR) { - zval_ptr_dtor_nogc(var); + zval tmp; + ZVAL_COPY_VALUE(&tmp, var); + ZVAL_UNDEF(var); + zval_ptr_dtor_nogc(&tmp); } else if (kind == ZEND_LIVE_NEW) { zend_object *obj; ZEND_ASSERT(Z_TYPE_P(var) == IS_OBJECT); @@ -4999,7 +5002,10 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { zend_hash_iterator_del(Z_FE_ITER_P(var)); } - zval_ptr_dtor_nogc(var); + zval tmp; + ZVAL_COPY_VALUE(&tmp, var); + ZVAL_UNDEF(var); + zval_ptr_dtor_nogc(&tmp); } else if (kind == ZEND_LIVE_ROPE) { zend_string **rope = (zend_string **)var; const zend_op *last = EX(func)->op_array.opcodes + op_num;

« previous php.cvs (#142956) next »