Skip to content

Commit

Permalink
ecere/net/network (Linux): Fixed race condition
Browse files Browse the repository at this point in the history
- On Linux, the polling file descriptors were a pointer to memory that still
  gets updated (e.g., by clrSocket()) while the network mutex is not locked and poll() is running.
  Prior to switching to poll(), there was still an issue in directly selecting
  on the socket file descriptors directly in the network object.
  • Loading branch information
jerstlouis committed Sep 12, 2023
1 parent da5960a commit 152fb12
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ecere/src/net/network.ec
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ static class NetworkThread : Thread
{
uint Main()
{
#if !defined(__WIN32__)
struct pollfd * pollFDs = null;
int nAllocatedFDs = 0;
#endif

network.mutex.Wait();
while(!network.networkTerminated)
{
Expand All @@ -220,8 +225,13 @@ static class NetworkThread : Thread

fd_set selectRS = network.readSet, selectWS = network.writeSet, selectES = network.exceptSet;
#else
struct pollfd * pollFDs = network.pollFDs;
int nPollFDs = network.numPollFDs;
if(nPollFDs > nAllocatedFDs)
{
nAllocatedFDs = nPollFDs;
pollFDs = renew pollFDs struct pollfd[nAllocatedFDs];
}
memcpy(pollFDs, network.pollFDs, sizeof(struct pollfd) * nPollFDs);
#endif

network.mutex.Release();
Expand Down Expand Up @@ -265,6 +275,7 @@ static class NetworkThread : Thread

}
network.mutex.Release();
delete pollFDs;
return 0;
}
}
Expand Down

0 comments on commit 152fb12

Please sign in to comment.