[php-src] PR #25801: Fix UAF/NULL deref on re-entrant watcher dtor in Io\Poll stream close

From: Date: Thu, 26 Nov 2026 19:36:41 +0000
Subject: [php-src] PR #25801: Fix UAF/NULL deref on re-entrant watcher dtor in Io\Poll stream close
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41076@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25801 Author: hohphu8 In php_io_poll_stream_notify_close() (ext/standard/io_poll.c), calling php_io_poll_context_retire_watcher() while iterating stream->poll_watchers destroys watcher->data. A __destruct() on that user data can re-entrantly call remove() on another watcher or drop another Io\Poll\Context watching the same stream, causing a NULL dereference or heap UAF (SIGSEGV) on later iterations. php_io_poll_watcher_modify_data() also destroys watcher->data before copying in the new value. This splits php_io_poll_stream_notify_close() into two passes (first detaching all watchers with watcher->stream = NULL, watcher->closed = true, and GC_ADDREF(&watcher->std); then retiring active watchers and calling OBJ_RELEASE), and swaps watcher->data to a local old_data before calling zval_ptr_dtor(&old_data) in php_io_poll_watcher_modify_data(). Adds ext/standard/tests/poll/poll_stream_close_reentrant_dtor.phpt covering both re-entrant remove() and context destruction during fclose(). Verified SIGSEGV -> PASS on PHP-8.6 (Debug + ZTS) with ext/standard/tests/poll/ passing (52/52). *Found via AI-assisted source inspection and verified it myself.*

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