From 5ee29e8a26d7cabba8a12c955bb71a7c60716649 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 16 Sep 2020 14:05:10 -0600 Subject: [PATCH] LibIPC: Check if socket is still open before using socket descriptor Writing to the socket may trigger a close of the socket descriptor if a disconnect was detected. We need to check if it is still valid when waiting for a response after attempting to send a synchronous message. Fixes #3515 --- Libraries/LibIPC/Connection.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Libraries/LibIPC/Connection.h b/Libraries/LibIPC/Connection.h index c02b633489..016669aa3d 100644 --- a/Libraries/LibIPC/Connection.h +++ b/Libraries/LibIPC/Connection.h @@ -140,6 +140,8 @@ protected: return m_unprocessed_messages.take(i).template release_nonnull(); } + if (!m_socket->is_open()) + break; fd_set rfds; FD_ZERO(&rfds); FD_SET(m_socket->fd(), &rfds); @@ -150,14 +152,15 @@ protected: ASSERT(rc > 0); ASSERT(FD_ISSET(m_socket->fd(), &rfds)); if (!drain_messages_from_peer()) - return nullptr; + break; } + return nullptr; } bool drain_messages_from_peer() { Vector bytes; - for (;;) { + while (m_socket->is_open()) { u8 buffer[4096]; ssize_t nread = recv(m_socket->fd(), buffer, sizeof(buffer), MSG_DONTWAIT); if (nread < 0) {