summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-09-16 14:05:10 -0600
committerAndreas Kling <kling@serenityos.org>2020-09-17 09:47:29 +0200
commit5ee29e8a26d7cabba8a12c955bb71a7c60716649 (patch)
tree139e8c6aa61d31e9ba9f53aaed0b26231fe2db50 /Libraries
parent17200306255b3a1d7ce71bc7cdabdb18807ce8d0 (diff)
downloadserenity-5ee29e8a26d7cabba8a12c955bb71a7c60716649.zip
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
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibIPC/Connection.h7
1 files 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<MessageType>();
}
+ 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<u8> 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) {