From 5dfdcf796df67661256237006e4b18a47de1f59f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 14 Mar 2019 19:57:54 +0100 Subject: [PATCH] TCP: Correct checksum for packets with odd number of bytes. --- Kernel/TCPSocket.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Kernel/TCPSocket.cpp b/Kernel/TCPSocket.cpp index 3dc5a90be4..9a37cd658a 100644 --- a/Kernel/TCPSocket.cpp +++ b/Kernel/TCPSocket.cpp @@ -50,6 +50,7 @@ int TCPSocket::protocol_receive(const ByteBuffer& packet_buffer, void* buffer, s auto& ipv4_packet = *(const IPv4Packet*)(packet_buffer.pointer()); auto& tcp_packet = *static_cast(ipv4_packet.payload()); size_t payload_size = packet_buffer.size() - sizeof(IPv4Packet) - tcp_packet.header_size(); + kprintf("payload_size %u, will it fit in %u?\n", payload_size, buffer_size); ASSERT(buffer_size >= payload_size); if (addr) { auto& ia = *(sockaddr_in*)addr; @@ -141,7 +142,7 @@ NetworkOrdered TCPSocket::compute_tcp_checksum(const IPv4Address& source, checksum = (checksum >> 16) + (checksum & 0xffff); } if (payload_size & 1) { - word expanded_byte = ((const byte*)packet.payload())[payload_size - 1]; + word expanded_byte = ((const byte*)packet.payload())[payload_size - 1] << 8; checksum += expanded_byte; if (checksum > 0xffff) checksum = (checksum >> 16) + (checksum & 0xffff);