From 9b6d1df5a727d8e64966e5c7f707db1547d9dd77 Mon Sep 17 00:00:00 2001 From: CPANSec Security Scanner Bot Date: Tue, 24 Nov 2026 14:29:55 +0000 Subject: [PATCH] Net::Server::Proto::SSLEAY: do not die on a failed TLS session SSLeay_check_perm classifies read and write failures with Net::SSLeay::get_error, which leaves the OpenSSL error queue as it is. close then calls SSLeay_check_fatal, which dies if the queue holds any error, so a connection that ends without a clean TLS session (a plaintext request, a malformed or failed handshake, or with OpenSSL 3 a bare connect and close) raises an exception after the request. The same happens in post_accept when Net::SSLeay::accept fails, before the allow/deny rules run. Nothing catches the exception: a PreFork child exits and a Single server stops. Drain the error queue in SSLeay_check_perm once a permanent error is found, adding the queued errors to the reported message. In close, report queued errors through SSLeay_check_error (which still calls SSL_error_callback) instead of dying. A failed handshake in SSLeay is reported the same way and recorded in error; the SSL handle is stored first so that close frees it, and later reads on the connection fail, so the request handler sees the connection as closed. Notes for deciding whether to apply this patch: - A connection that ends without a clean TLS session is now reported through SSL_error_callback without the fatal flag, instead of raising an exception. A failed handshake is reported and the request handler sees a closed connection. - The SSL handle is stored before the handshake, so it is now freed after a failed handshake. Before, it leaked. - This patch and the one for the double free on close 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Net/Server/Proto/SSLEAY.pm b/lib/Net/Server/Proto/SSLEAY.pm index c395b6e..d300c5a 100644 --- a/lib/Net/Server/Proto/SSLEAY.pm +++ b/lib/Net/Server/Proto/SSLEAY.pm @@ -169,7 +169,7 @@ sub close { } else { Net::SSLeay::CTX_free($sock->SSLeay_context); } - $sock->SSLeay_check_fatal("SSLeay close free"); + $sock->SSLeay_check_error("SSLeay close free"); # drain the error queue, but do not die on a session the peer ended badly return $sock->SUPER::close(@_); } @@ -211,8 +211,11 @@ sub SSLeay { my $ssl = Net::SSLeay::new($client->SSLeay_context); $client->SSLeay_check_fatal("SSLeay new"); Net::SSLeay::set_fd($ssl, $client->fileno); $client->SSLeay_check_fatal("SSLeay set_fd"); - Net::SSLeay::accept($ssl); $client->SSLeay_check_fatal("SSLeay accept"); ${*$client}{'SSLeay'} = $ssl; + Net::SSLeay::accept($ssl); + if (my $err = $client->SSLeay_check_error("SSLeay accept")) { # failed handshake - treat as a closed connection + ${*$client}{'_error'} = "SSLeay accept: ".join(' ', @$err); + } } return if ! defined wantarray; @@ -264,6 +267,9 @@ sub SSLeay_check_perm { } return if $!{'EAGAIN'} || $!{'EINTR'} || $!{'ENOBUFS'}; # Retryable safe errno ($perm = "FD$fn-sslerr[$err] - ".Net::SSLeay::ERR_error_string($err)." [$!] $@")=~s/\s+$//; + while (my $n = Net::SSLeay::ERR_get_error()) { # drain the error queue so later checks do not see stale errors + $perm .= " - ".Net::SSLeay::ERR_error_string($n); + } } return if !$perm; -- 2.53.0