From 3b59282e2f99c111ddc1d0f92dbe04f465ebd81c Mon Sep 17 00:00:00 2001 From: CPANSec Security Scanner Bot Date: Tue, 24 Nov 2026 14:31:09 +0000 Subject: [PATCH] Net::Server::Proto::SSLEAY: do not free the SSL handle twice on close close freed the SSL handle stored on a client socket but left the pointer in place, so a second close on the same client ran is_init_finished, shutdown and free on the freed handle. That happens in every PSGI streaming response: Net::Server::PSGI passes the client socket to the application as the writer, the application closes the writer as the PSGI specification asks, and the server closes the client again after the request. The double free corrupts the heap and crashes the server process. Remove the handle from the socket before freeing it, so that a repeated close is a no-op for the SSL session. Notes for deciding whether to apply this patch: - Writing to a client after it has been closed now dies with a Perl error instead of using freed memory. - This patch and the one for the OpenSSL error queue both change close in Net::Server::Proto::SSLEAY. Apply them in CVE-ID order. - Not tested on a running server. It was checked by review and by applying it to Net-Server 2.018. - Applies on its own to Net-Server 2.018, and together with the other CPANSec patches for Net-Server 2.018 when they are applied in CVE-ID order. --- lib/Net/Server/Proto/SSLEAY.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Net/Server/Proto/SSLEAY.pm b/lib/Net/Server/Proto/SSLEAY.pm index c395b6e..3d2bd1b 100644 --- a/lib/Net/Server/Proto/SSLEAY.pm +++ b/lib/Net/Server/Proto/SSLEAY.pm @@ -160,7 +160,7 @@ sub bind_SSL { sub close { my $sock = shift; if ($sock->SSLeay_is_client) { - if (my $ssl = ${*$sock}{'SSLeay'}) { # Avoid trying to build a new ctx just to throw it away + if (my $ssl = delete ${*$sock}{'SSLeay'}) { # Avoid trying to build a new ctx just to throw it away; delete so a second close does not free it again my $should_shutdown = 1; # Net::SSLeay <= 1.85 does not have is_init_finished(), so just attempt shutdown in this case: eval { $should_shutdown = 0 if !Net::SSLeay::is_init_finished($ssl) }; Net::SSLeay::shutdown($ssl) if $should_shutdown; -- 2.53.0