Unverified Commit 6b6a5227 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #1476

Fix bug when the first frame is invalid
parents 9498fc8a c89a1d1f
......@@ -85,6 +85,14 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
}
return handle(hdr.opcode, payload, frame_size);
}
if (opcode_ == nil_code
&& hdr.opcode == detail::rfc6455::continuation_frame) {
CAF_LOG_DEBUG("received WebSocket continuation "
"frame without prior opcode");
abort_and_shutdown(sec::protocol_error, "received WebSocket continuation "
"frame without prior opcode");
return -1;
}
if (hdr.fin) {
if (opcode_ == nil_code) {
// Call upper layer.
......@@ -106,13 +114,6 @@ ptrdiff_t framing::consume(byte_span buffer, byte_span) {
// The first frame must not be a continuation frame. Any frame that is not
// the first frame must be a continuation frame.
if (opcode_ == nil_code) {
if (hdr.opcode == detail::rfc6455::continuation_frame) {
CAF_LOG_DEBUG("received WebSocket continuation "
"frame without prior opcode");
abort_and_shutdown(sec::protocol_error, "received WebSocket continuation "
"frame without prior opcode");
return -1;
}
opcode_ = hdr.opcode;
} else if (hdr.opcode != detail::rfc6455::continuation_frame) {
CAF_LOG_DEBUG("expected a continuation frame");
......
......@@ -449,7 +449,19 @@ SCENARIO("apps reject frames whose payload exceeds maximum allowed size") {
SCENARIO("the application shuts down on invalid frame fragments") {
GIVEN("a client that sends invalid fragmented frames") {
WHEN("the first fragment is a continuation frame") {
WHEN("the first fragment is a continuation frame with FIN flag") {
reset();
byte_buffer input;
const auto data = make_test_data(10);
detail::rfc6455::assemble_frame(detail::rfc6455::continuation_frame, 0x0,
data, input);
transport->push(input);
THEN("the app closes the connection with a protocol error") {
CHECK_EQ(transport->handle_input(), 0);
CHECK_EQ(app->abort_reason, sec::protocol_error);
}
}
WHEN("the first fragment is a continuation frame without FIN flag") {
reset();
byte_buffer input;
const auto data = make_test_data(10);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment