1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

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
This commit is contained in:
Tom 2020-09-16 14:05:10 -06:00 committed by Andreas Kling
parent 1720030625
commit 5ee29e8a26

View file

@ -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) {