1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

LibWebSocket: Don't try to send empty payload inside of frame

According to RFC 6455 sections 5.5.2-5.5.3 Ping and Pong frames
can have empty "Application data" that means payload can be of size 0.
This change fixes failed "buffer.size()" assertion inside
of Core::Stream::write_or_error by not trying to send empty payload
in WebSocket::send_frame.
This commit is contained in:
DerpyCrabs 2022-02-12 13:00:37 +03:00 committed by Andreas Kling
parent e379147f64
commit 29078d4d53

View file

@ -541,6 +541,9 @@ void WebSocket::send_frame(WebSocket::OpCode op_code, ReadonlyBytes payload, boo
u8 masking_key[4];
fill_with_random(masking_key, 4);
m_impl->send(ReadonlyBytes(masking_key, 4));
// don't try to send empty payload
if (payload.size() == 0)
return;
// Mask the payload
auto buffer_result = ByteBuffer::create_uninitialized(payload.size());
if (!buffer_result.is_error()) {
@ -550,7 +553,7 @@ void WebSocket::send_frame(WebSocket::OpCode op_code, ReadonlyBytes payload, boo
}
m_impl->send(masked_payload);
}
} else {
} else if (payload.size() > 0) {
m_impl->send(payload);
}
}