[php-src] PR #22316: Fix Io\Poll memory-safety and error-handling issues

From: Date: Mon, 15 Jun 2026 10:58:23 +0000
Subject: [php-src] PR #22316: Fix Io\Poll memory-safety and error-handling issues
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-36434@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/22316 Author: iliaal Fixes memory-safety and error-handling bugs in the new Io\Poll API, found by review and confirmed under valgrind on the epoll backend. - Use-after-free: a Watcher kept a raw pointer to its Context's poll context with no reference, so dropping the Context while still holding a Watcher made remove()/modify() touch freed memory. The Context now clears its watchers (active=false, poll_ctx=NULL) before destruction, so those calls throw InactiveWatcherException. - Descriptor leak: StreamPollHandle referenced the stream resource in its constructor but never released it. Released in the handle cleanup. - Missing get_gc on Watcher and Context, so cycles through Watcher::$data leaked. Added for both. - epoll and poll wait() returned -1 without recording the error, so the thrown exception reported a stale code. Now set from errno. - kqueue grouped-event path guarded the result buffer with only a ZEND_ASSERT, allowing an out-of-bounds write in release builds when more distinct descriptors were ready than maxEvents. Bounded at runtime, matching the raw-event path. This one is from code inspection: the kqueue backend isn't compiled on Linux, so I couldn't reproduce it here, only the epoll/poll fixes are valgrind-confirmed. - NULL guard in php_poll_create_by_name(). Tests cover the UAF, the fd leak, and the get_gc cycle on Linux.

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