1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:37:45 +00:00

Everywhere: Use OOM-safe ByteBuffer APIs where possible

If we can easily communicate failure, let's avoid asserting and report
failure instead.
This commit is contained in:
Ali Mohammad Pur 2021-09-06 03:28:46 +04:30 committed by Andreas Kling
parent 6606993432
commit 3a9f00c59b
22 changed files with 135 additions and 67 deletions

View file

@ -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: