Skip to content

Commit 8e90bc4

Browse files
committed
Fix crash with sv_dnsbl_vote 1 and debug dummies
In the `CServer::DistinctClientCount` function a check for the address being `nullptr` was missing in the inner loop. Before ddnet#9591 this was comparing addresses from uninitialized memory instead. Duplicate checks of the client state are avoided by first fetching the addesses of all clients which are ingame. Closes ddnet#9597.
1 parent 82d8112 commit 8e90bc4

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/engine/server/server.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -726,30 +726,27 @@ int CServer::DistinctClientCount() const
726726
const NETADDR *apAddresses[MAX_CLIENTS];
727727
for(int i = 0; i < MAX_CLIENTS; i++)
728728
{
729-
if(m_aClients[i].m_State != CClient::STATE_EMPTY)
730-
{
731-
apAddresses[i] = ClientAddr(i);
732-
}
729+
// connecting clients with spoofed ips can clog slots without being ingame
730+
apAddresses[i] = ClientIngame(i) ? ClientAddr(i) : nullptr;
733731
}
734732

735733
int ClientCount = 0;
736734
for(int i = 0; i < MAX_CLIENTS; i++)
737735
{
738-
// connecting clients with spoofed ips can clog slots without being ingame
739-
if(ClientIngame(i))
736+
if(apAddresses[i] == nullptr)
740737
{
741-
ClientCount++;
742-
for(int j = 0; j < i; j++)
738+
continue;
739+
}
740+
ClientCount++;
741+
for(int j = 0; j < i; j++)
742+
{
743+
if(apAddresses[j] != nullptr && !net_addr_comp_noport(apAddresses[i], apAddresses[j]))
743744
{
744-
if(!net_addr_comp_noport(apAddresses[i], apAddresses[j]))
745-
{
746-
ClientCount--;
747-
break;
748-
}
745+
ClientCount--;
746+
break;
749747
}
750748
}
751749
}
752-
753750
return ClientCount;
754751
}
755752

0 commit comments

Comments
 (0)