Skip to content

Commit 1958e12

Browse files
committed
inspector: simplify ws length guard, make test fail without fix
Signed-off-by: nashit hayyat <nashit@bugqore.com>
1 parent bfe6764 commit 1958e12

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/inspector_socket.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ static ws_decode_result decode_frame_hybi17(const std::vector<char>& buffer,
363363
// The masking key and the payload follow the header `it` already walked
364364
// past, so they have to fit in what is left rather than in the whole buffer.
365365
size_t remaining = static_cast<size_t>(buffer.end() - it);
366-
if (remaining < kMaskingKeyWidthInBytes ||
367-
remaining - kMaskingKeyWidthInBytes < payload_length)
366+
if (remaining < kMaskingKeyWidthInBytes + payload_length)
368367
return FRAME_INCOMPLETE;
369368

370369
std::vector<char>::const_iterator masking_key = it;

‎test/cctest/test_inspector_socket.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ TEST_F(InspectorSocketTest, WaitsForFrameBodyToArrive) {
419419
const char FRAME_HEADER[] = {'\x81', '\x85'};
420420
do_write(FRAME_HEADER, sizeof(FRAME_HEADER));
421421

422+
// Round trip through the server so the header is guaranteed to have been
423+
// read on its own, instead of arriving together with the body below.
424+
const char SERVER_MESSAGE[] = "ping";
425+
const char SERVER_FRAME[] = {'\x81', '\x04', 'p', 'i', 'n', 'g'};
426+
delegate->Write(SERVER_MESSAGE, sizeof(SERVER_MESSAGE) - 1);
427+
expect_on_client(SERVER_FRAME, sizeof(SERVER_FRAME));
428+
422429
const char FRAME_BODY[] = {'\x01', '\x02', '\x03', '\x04',
423430
'\x69', '\x67', '\x6F', '\x68', '\x6E'};
424431
do_write(FRAME_BODY, sizeof(FRAME_BODY));

0 commit comments

Comments
 (0)