From 32e6fd9715c9c20d27908f2c010833d26aa6b5e3 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 10 Nov 2023 10:38:37 +0330 Subject: [PATCH] LibTLS: Do not defer flushing alert packets There's a good chance the TLS socket instance will be deleted before the deferred invocation fires, and there's no real reason to defer flushes of alerts anyway as they are usually sent on errors. Fixes #21800. --- Userland/Libraries/LibTLS/Record.cpp | 6 +++--- Userland/Libraries/LibTLS/TLSv12.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibTLS/Record.cpp b/Userland/Libraries/LibTLS/Record.cpp index 0426787b4e..94596654b4 100644 --- a/Userland/Libraries/LibTLS/Record.cpp +++ b/Userland/Libraries/LibTLS/Record.cpp @@ -32,11 +32,11 @@ ByteBuffer TLSv12::build_alert(bool critical, u8 code) void TLSv12::alert(AlertLevel level, AlertDescription code) { auto the_alert = build_alert(level == AlertLevel::FATAL, (u8)code); - write_packet(the_alert); + write_packet(the_alert, true); MUST(flush()); } -void TLSv12::write_packet(ByteBuffer& packet) +void TLSv12::write_packet(ByteBuffer& packet, bool immediately) { auto schedule_or_perform_flush = [&](bool immediate) { if (m_context.connection_status > ConnectionStatus::Disconnected) { @@ -61,7 +61,7 @@ void TLSv12::write_packet(ByteBuffer& packet) // Toooooo bad, drop the record on the ground. return; } - schedule_or_perform_flush(false); + schedule_or_perform_flush(immediately); } void TLSv12::update_packet(ByteBuffer& packet) diff --git a/Userland/Libraries/LibTLS/TLSv12.h b/Userland/Libraries/LibTLS/TLSv12.h index ab1edad686..7c0b42376b 100644 --- a/Userland/Libraries/LibTLS/TLSv12.h +++ b/Userland/Libraries/LibTLS/TLSv12.h @@ -361,7 +361,7 @@ private: void update_packet(ByteBuffer& packet); void update_hash(ReadonlyBytes in, size_t header_size); - void write_packet(ByteBuffer& packet); + void write_packet(ByteBuffer& packet, bool immediately = false); ByteBuffer build_client_key_exchange(); ByteBuffer build_server_key_exchange();