Skip to content

Commit

Permalink
LibCore: Prevent SIGPIPE on Sockets by default
Browse files Browse the repository at this point in the history
While this is the default for an underlying socket, it doesn't seem good
to have this as the default for our socket wrapper.

This fixes a crash in ladybird when connecting to the python HTTP server
with HTTPS.
  • Loading branch information
shannonbooth authored and timschumi committed Apr 5, 2024
1 parent f3053f1 commit aab5d4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/LocalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ErrorOr<NonnullOwnPtr<LocalSocket>> LocalServer::accept()
(void)fcntl(accepted_fd, F_SETFD, FD_CLOEXEC);
#endif

return LocalSocket::adopt_fd(accepted_fd, Socket::PreventSIGPIPE::Yes);
return LocalSocket::adopt_fd(accepted_fd);
}

}
14 changes: 7 additions & 7 deletions Userland/Libraries/LibCore/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Socket : public Stream {
Inet,
};

Socket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
explicit Socket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::Yes)
: m_prevent_sigpipe(prevent_sigpipe == PreventSIGPIPE::Yes)
{
}
Expand All @@ -87,7 +87,7 @@ class Socket : public Stream {
}

private:
bool m_prevent_sigpipe { false };
bool m_prevent_sigpipe { true };
};

/// A reusable socket maintains state about being connected in addition to
Expand Down Expand Up @@ -195,7 +195,7 @@ class TCPSocket final : public Socket {
virtual ~TCPSocket() override { close(); }

private:
TCPSocket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
explicit TCPSocket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::Yes)
: Socket(prevent_sigpipe)
{
}
Expand Down Expand Up @@ -269,7 +269,7 @@ class UDPSocket final : public Socket {
virtual ~UDPSocket() override { close(); }

private:
UDPSocket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
explicit UDPSocket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::Yes)
: Socket(prevent_sigpipe)
{
}
Expand All @@ -290,8 +290,8 @@ class UDPSocket final : public Socket {

class LocalSocket final : public Socket {
public:
static ErrorOr<NonnullOwnPtr<LocalSocket>> connect(ByteString const& path, PreventSIGPIPE = PreventSIGPIPE::No);
static ErrorOr<NonnullOwnPtr<LocalSocket>> adopt_fd(int fd, PreventSIGPIPE = PreventSIGPIPE::No);
static ErrorOr<NonnullOwnPtr<LocalSocket>> connect(ByteString const& path, PreventSIGPIPE = PreventSIGPIPE::Yes);
static ErrorOr<NonnullOwnPtr<LocalSocket>> adopt_fd(int fd, PreventSIGPIPE = PreventSIGPIPE::Yes);

LocalSocket(LocalSocket&& other)
: Socket(static_cast<Socket&&>(other))
Expand Down Expand Up @@ -343,7 +343,7 @@ class LocalSocket final : public Socket {
virtual ~LocalSocket() { close(); }

private:
LocalSocket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::No)
explicit LocalSocket(PreventSIGPIPE prevent_sigpipe = PreventSIGPIPE::Yes)
: Socket(prevent_sigpipe)
{
}
Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibWeb/HTML/MessagePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ WebIDL::ExceptionOr<void> MessagePort::transfer_receiving_steps(HTML::TransferDa
auto fd_tag = data_holder.data.take_first();
if (fd_tag == IPC_FILE_TAG) {
auto fd = data_holder.fds.take_first();
m_socket = MUST(Core::LocalSocket::adopt_fd(fd.take_fd(), Core::LocalSocket::PreventSIGPIPE::Yes));
m_socket = MUST(Core::LocalSocket::adopt_fd(fd.take_fd()));

fd_tag = data_holder.data.take_first();
VERIFY(fd_tag == IPC_FILE_TAG);
fd = data_holder.fds.take_first();
m_fd_passing_socket = MUST(Core::LocalSocket::adopt_fd(fd.take_fd(), Core::LocalSocket::PreventSIGPIPE::Yes));
m_fd_passing_socket = MUST(Core::LocalSocket::adopt_fd(fd.take_fd()));

m_socket->on_ready_to_read = [strong_this = JS::make_handle(this)]() {
strong_this->read_from_socket();
Expand Down Expand Up @@ -155,10 +155,10 @@ void MessagePort::entangle_with(MessagePort& remote_port)
auto create_paired_sockets = []() -> Array<NonnullOwnPtr<Core::LocalSocket>, 2> {
int fds[2] = {};
MUST(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, fds));
auto socket0 = MUST(Core::LocalSocket::adopt_fd(fds[0], Core::LocalSocket::PreventSIGPIPE::Yes));
auto socket0 = MUST(Core::LocalSocket::adopt_fd(fds[0]));
MUST(socket0->set_blocking(false));
MUST(socket0->set_close_on_exec(true));
auto socket1 = MUST(Core::LocalSocket::adopt_fd(fds[1], Core::LocalSocket::PreventSIGPIPE::Yes));
auto socket1 = MUST(Core::LocalSocket::adopt_fd(fds[1]));
MUST(socket1->set_blocking(false));
MUST(socket1->set_close_on_exec(true));

Expand Down

0 comments on commit aab5d4e

Please sign in to comment.