diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-05 13:03:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-05 22:11:49 +0200 |
commit | 0625342382e712a99a83003e828d8ef19f580bf6 (patch) | |
tree | 3d9cdd9e73c205e83c9a7edaae318a9487eb9f0a /Kernel/Net/IPv4Socket.cpp | |
parent | 51c2c69357963ecaffba522aa963a3eba1c3bc8e (diff) | |
download | serenity-0625342382e712a99a83003e828d8ef19f580bf6.zip |
Kernel: Return EPIPE when trying to write to an unconnected socket
When attempting to write to a socket that is not connected or - for
connection-less protocols - doesn't have a peer address set we should
return EPIPE instead of blocking the thread.
Diffstat (limited to 'Kernel/Net/IPv4Socket.cpp')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 54326ce9a2..260c878e22 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -170,7 +170,7 @@ bool IPv4Socket::can_read(const FileDescription&, size_t) const bool IPv4Socket::can_write(const FileDescription&, size_t) const { - return is_connected(); + return true; } PortAllocationResult IPv4Socket::allocate_local_port_if_needed() @@ -206,6 +206,9 @@ KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& m_peer_port = ntohs(ia.sin_port); } + if (!is_connected() && m_peer_address.is_zero()) + return EPIPE; + auto routing_decision = route_to(m_peer_address, m_local_address, bound_interface()); if (routing_decision.is_zero()) return EHOSTUNREACH; |