]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/bio/bss_acpt: reset accept_sock and b->num after close in ACPT_S_LISTEN failures
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Sat, 11 Oct 2025 21:39:25 +0000 (05:39 +0800)
committerNeil Horman <nhorman@openssl.org>
Mon, 24 Nov 2025 14:19:34 +0000 (09:19 -0500)
On BIO_listen or BIO_sock_info failure we close the socket but leave
accept_sock and b->num pointing at the old fd. Later cleanup can double
close.

Set both to INVALID_SOCKET immediately after BIO_closesocket.

Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28904)

(cherry picked from commit 1c4f7b10358b79a0b33619187caa2b7e3bdb6e7a)

crypto/bio/bss_acpt.c

index 7c55cc05def3c562a3bccd62342db3d3c6c16cb2..881cfe50ca4b75f17bb60b316665abbdeae69241 100644 (file)
@@ -248,6 +248,8 @@ static int acpt_state(BIO *b, BIO_ACCEPT *c)
                                 BIO_ADDRINFO_address(c->addr_iter),
                                 c->bind_mode)) {
                     BIO_closesocket(c->accept_sock);
+                    c->accept_sock = (int)INVALID_SOCKET;
+                    b->num = (int)INVALID_SOCKET;
                     goto exit_loop;
                 }
             }
@@ -259,6 +261,8 @@ static int acpt_state(BIO *b, BIO_ACCEPT *c)
                 if (!BIO_sock_info(c->accept_sock, BIO_SOCK_INFO_ADDRESS,
                                    &info)) {
                     BIO_closesocket(c->accept_sock);
+                    c->accept_sock = (int)INVALID_SOCKET;
+                    b->num = (int)INVALID_SOCKET;
                     goto exit_loop;
                 }
             }