Prevent writing to a socket marked as closed 34/251534/8
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 14 Jan 2021 12:54:15 +0000 (13:54 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 25 Jan 2021 21:30:57 +0000 (22:30 +0100)
It is possible that select() marks a descriptor as ready for both read
and write operation. If, additionally, the socket becomes closed in
ReadyForRead(), the following call to ReadyForWrite() will attempt to
write to a closed socket. It is harmless, unless the closed descriptor
is already reused by another thread at the time of write().

This commit prevents it.

Change-Id: Idaa829ef74d6df9f24c263f289aeca910b679713

src/manager/main/socket-manager.cpp

index 440e902..1d4d0f6 100644 (file)
@@ -491,7 +491,9 @@ void SocketManager::MainLoop()
                        }
 
                        if (FD_ISSET(i, &writeSet)) {
-                               ReadyForWrite(i);
+                               // it is possible that the socket was closed in preceding call to ReadyForRead()
+                               if (m_socketDescriptionVector[i].isOpen())
+                                       ReadyForWrite(i);
                                --ret;
                        }
                }