summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibTLS/Record.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-06 03:28:46 +0430
committerAndreas Kling <kling@serenityos.org>2021-09-06 01:53:26 +0200
commit3a9f00c59bad7735970c72cb940d08161fda09b0 (patch)
tree5eebf972a2a3b3c2e73d40068f4d58c9d6368764 /Userland/Libraries/LibTLS/Record.cpp
parent6606993432273959d7b2e1815646ee8a54025103 (diff)
downloadserenity-3a9f00c59bad7735970c72cb940d08161fda09b0.zip
Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report failure instead.
Diffstat (limited to 'Userland/Libraries/LibTLS/Record.cpp')
-rw-r--r--Userland/Libraries/LibTLS/Record.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Libraries/LibTLS/Record.cpp b/Userland/Libraries/LibTLS/Record.cpp
index 02314b52c6..53bb06b531 100644
--- a/Userland/Libraries/LibTLS/Record.cpp
+++ b/Userland/Libraries/LibTLS/Record.cpp
@@ -37,7 +37,11 @@ void TLSv12::alert(AlertLevel level, AlertDescription code)
void TLSv12::write_packet(ByteBuffer& packet)
{
- m_context.tls_buffer.append(packet.data(), packet.size());
+ auto ok = m_context.tls_buffer.try_append(packet.data(), packet.size());
+ if (!ok) {
+ // Toooooo bad, drop the record on the ground.
+ return;
+ }
if (m_context.connection_status > ConnectionStatus::Disconnected) {
if (!m_has_scheduled_write_flush) {
dbgln_if(TLS_DEBUG, "Scheduling write of {}", m_context.tls_buffer.size());
@@ -451,7 +455,11 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
} else {
dbgln_if(TLS_DEBUG, "application data message of size {}", plain.size());
- m_context.application_buffer.append(plain.data(), plain.size());
+ if (!m_context.application_buffer.try_append(plain.data(), plain.size())) {
+ payload_res = (i8)Error::DecryptionFailed;
+ auto packet = build_alert(true, (u8)AlertDescription::DecryptionFailed);
+ write_packet(packet);
+ }
}
break;
case MessageType::Handshake: