Skip to content

Fix GH-25677: Use-after-free when a destructor calls error_get_last() while the fatal error backtrace is released - #26000

Open
Harp404 wants to merge 1 commit into
php:PHP-8.5from
Harp404:fix-gh25677
Open

Harp404 wants to merge 1 commit into
php:PHP-8.5from
Harp404:fix-gh25677

Conversation

@Harp404

@Harp404 Harp404 commented Dec 1, 2026

Copy link
Copy Markdown

Fixes GH-25677.

zend_error_zstr_at() released EG(last_fatal_error_backtrace) before unsetting it. When the backtrace's frame args hold the last reference to an object, its destructor runs during that release, and error_get_last() called from the destructor copies the array that is being destroyed. The fix moves the backtrace to a local zval and unsets the global first, so error_get_last() no longer returns a trace key there.

Zend/tests/backtrace/gh25677.phpt is the reproducer from the issue. Without the fix it fails, and the issue's script reports a heap-use-after-free with an ASan build (USE_ZEND_ALLOC=0). With the fix it passes, as do Zend/tests/backtrace, Zend/tests/gh*.phpt and error_get_last_002.phpt under --asan.

Targets PHP-8.5, where fatal error backtraces were added.

I used Claude Code (Opus 5.5) to help investigate and draft this change; the quoted text above was written with it. I reproduced the bug and checked the fix myself.

…t() while the fatal error backtrace is released

Unset EG(last_fatal_error_backtrace) before releasing it, so a destructor
run by the release no longer finds the array being destroyed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant