[php-src] PR #25792: Do not close a socket descriptor twice after a failed bind or connect

From: Date: Thu, 26 Nov 2026 15:57:21 +0000
Subject: [php-src] PR #25792: Do not close a socket descriptor twice after a failed bind or connect
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41061@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25792 Author: lacatoire When bind(), connect() or listen() fails, socket_addrinfo_bind(), socket_addrinfo_connect() and socket_create_listen() close the descriptor, then destroy the new Socket, whose destructor closes the same descriptor again because bsd_socket is never reset. In a thread-safe build, another thread can get that descriptor number in between and lose it. This resets bsd_socket to -1 after each explicit close. ### To reproduce ```php <?php $ai = socket_addrinfo_lookup('127.0.0.1', '1', ['ai_socktype' => SOCK_STREAM, 'ai_family' => AF_INET]); var_dump(@socket_addrinfo_connect($ai[0])); ``` Under strace -e trace=close, before (PHP 8.4.28): ``` close(5) = 0 close(5) = -1 EBADF (Bad file descriptor) ``` After: a single close(5). The added test checks that the failure paths still return false; the double close itself is only visible under strace.

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