[php-src] PR #22400: Fix use-after-free on re-entrant ftp_close() during a transfer

From: Date: Mon, 22 Jun 2026 15:21:52 +0000
Subject: [php-src] PR #22400: Fix use-after-free on re-entrant ftp_close() during a transfer
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-36554@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/22400 Author: iliaal ftp_get(), ftp_put(), ftp_append() and the ftp_nb_* variants cache the ftpbuf_t on the C stack and stream the received or sent bytes through a caller-supplied php_stream. When that stream is a user-registered wrapper, its stream_read/stream_write handler can call ftp_close() on the same connection mid-transfer, freeing the ftpbuf_t and databuf_t while the engine still holds them, so the transfer resumes on freed memory. Valgrind confirms invalid reads in the ftp_get() receive loop, freed by the re-entrant ftp_close(). The fix sets an in_use flag around each engine transfer (including ftp_nb_continue_read/ftp_nb_continue_write, which the non-blocking entry points run through) and makes ftp_close() throw while it is set. Smallest trigger: a wrapper whose stream_write calls ftp_close($conn) during ftp_get($conn, 'wrapper://x', ...). Reported privately as GHSA-vr2x-x6ff-4586 and rejected per the project security policy (the trigger is PHP code, not the FTP server), so filing as a normal bug.

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