[php-src] PR #21686: Fix GH-16321: UAF in list_entry_destructor when resource dtor adds references

From: Date: Thu, 09 Apr 2026 13:15:08 +0000
Subject: [php-src] PR #21686: Fix GH-16321: UAF in list_entry_destructor when resource dtor adds references
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35635@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21686 Author: iliaal Fixes #16321 list_entry_destructor() freed the resource struct unconditionally after calling its destructor. If user code ran during the destructor (e.g. a stream filter callback) and something captured a new reference to the resource (e.g. an exception backtrace), the struct was freed while still referenced, causing a heap-use-after-free in _build_trace_args(). Bumps the resource refcount before calling the destructor so reentrant calls to zend_list_free() can't trigger a premature free. After the destructor returns, skips the free if the refcount is still elevated. Adds a fallback path in zend_list_free() to free directly when the resource has already been removed from the list.

« previous php.git-pulls (#35635) next »