Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close TCP connection when received message size is too large. #33768

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/transport/raw/TCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ CHIP_ERROR TCPBase::ProcessReceivedBuffer(Inet::TCPEndPoint * endPoint, const Pe
uint32_t messageSize = LittleEndian::Get32(messageSizeBuf);
if (messageSize >= kMaxTCPMessageSize)
{
// This message is too long for upper layers.
// Message is too big for this node to process. Disconnect from peer.
ChipLogError(Inet, "Received TCP message of length %" PRIu32 " exceeds limit.", messageSize);
CloseConnectionInternal(state, CHIP_ERROR_MESSAGE_TOO_LONG, SuppressCallback::No);

return CHIP_ERROR_MESSAGE_TOO_LONG;
}
// The subtraction will not underflow because we successfully read kPacketSizeBytes.
Expand Down
4 changes: 3 additions & 1 deletion src/transport/raw/tests/TestTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ TEST_F(TestTCP, CheckProcessReceivedBuffer)
EXPECT_EQ(err, CHIP_ERROR_MESSAGE_TOO_LONG);
EXPECT_EQ(gMockTransportMgrDelegate.mReceiveHandlerCallCount, 0);

gMockTransportMgrDelegate.DisconnectTest(tcp, addr);
// The receipt of a message exceeding the allowed size should have
// closed the connection.
EXPECT_EQ(TestAccess::GetEndpoint(state), nullptr);
}

} // namespace
Loading