From 516d68f7eb6f7434bf0929788a4049fd43f13a62 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 24 Feb 2025 11:24:20 +0100 Subject: [PATCH] LibTLS: Make TLSv12::can_read_without_blocking() actually work Previously this function's return value was not reliable, as available data on the underlying socket did not necessarily translate to available application data on the TLS socket. This commit makes it so this function only returns true when we actually have data buffered and/or available. --- Libraries/LibTLS/TLSv12.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/LibTLS/TLSv12.cpp b/Libraries/LibTLS/TLSv12.cpp index cfc1e37ae9e..b263cdf4a13 100644 --- a/Libraries/LibTLS/TLSv12.cpp +++ b/Libraries/LibTLS/TLSv12.cpp @@ -134,7 +134,13 @@ ErrorOr TLSv12::can_read_without_blocking(int timeout) const if (!m_ssl) return Error::from_string_literal("SSL connection is closed"); - return m_socket->can_read_without_blocking(timeout); + if (SSL_has_pending(m_ssl)) + return true; + + if (timeout > 0) + return TRY(m_socket->can_read_without_blocking(timeout)) && SSL_has_pending(m_ssl); + + return false; } ErrorOr TLSv12::set_blocking(bool)