diff options
author | Conrad Pankoff <deoxxa@fknsrs.biz> | 2019-09-08 19:37:05 +1000 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-08 12:34:20 +0200 |
commit | 3f1c3a341b396fefd2fa27afcbfb10eaec4dca70 (patch) | |
tree | e353340b83d22497516aa3139dc7008efae1099b /Kernel/Net/NetworkTask.cpp | |
parent | feb6d1afe0c68488a3313183e61f4de98cb1546b (diff) | |
download | serenity-3f1c3a341b396fefd2fa27afcbfb10eaec4dca70.zip |
Kernel: Handle listening socket disappearing during incoming handshake
Diffstat (limited to 'Kernel/Net/NetworkTask.cpp')
-rw-r--r-- | Kernel/Net/NetworkTask.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 012829bd06..f5b404fcd8 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -453,11 +453,32 @@ void handle_tcp(const IPv4Packet& ipv4_packet) switch (tcp_packet.flags()) { case TCPFlags::ACK: socket->set_ack_number(tcp_packet.sequence_number() + payload_size); - socket->set_state(TCPSocket::State::Established); - socket->set_setup_state(Socket::SetupState::Completed); - if (socket->direction() == TCPSocket::Direction::Outgoing) + + switch (socket->direction()) { + case TCPSocket::Direction::Incoming: + if (!socket->has_originator()) { + kprintf("handle_tcp: connection doesn't have an originating socket; maybe it went away?\n"); + socket->send_tcp_packet(TCPFlags::RST); + socket->set_state(TCPSocket::State::Closed); + return; + } + + socket->set_state(TCPSocket::State::Established); + socket->set_setup_state(Socket::SetupState::Completed); + socket->release_to_originator(); + return; + case TCPSocket::Direction::Outgoing: + socket->set_state(TCPSocket::State::Established); + socket->set_setup_state(Socket::SetupState::Completed); socket->set_connected(true); - socket->release_to_originator(); + return; + default: + kprintf("handle_tcp: got ACK in SynReceived state but direction is invalid (%s)\n", TCPSocket::to_string(socket->direction())); + socket->send_tcp_packet(TCPFlags::RST); + socket->set_state(TCPSocket::State::Closed); + return; + } + return; default: kprintf("handle_tcp: unexpected flags in SynReceived state\n"); |