Skip to content

Commit

Permalink
Add assertions to CServer::GetClientAddr functions
Browse files Browse the repository at this point in the history
Prevent use of uninitialized memory if the functions are used for a player that is not yet ingame. The check for the ingame state is also unnecessarily restrictive, as the client address should be available immediately.
  • Loading branch information
Robyt3 committed Dec 20, 2024
1 parent b52f1a4 commit 85e246e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,9 @@ void CServer::SetClientDDNetVersion(int ClientId, int DDNetVersion)

void CServer::GetClientAddr(int ClientId, char *pAddrStr, int Size) const
{
if(ClientId >= 0 && ClientId < MAX_CLIENTS && m_aClients[ClientId].m_State == CClient::STATE_INGAME)
net_addr_str(m_NetServer.ClientAddr(ClientId), pAddrStr, Size, false);
NETADDR Addr;
GetClientAddr(ClientId, &Addr);
net_addr_str(&Addr, pAddrStr, Size, false);
}

const char *CServer::ClientName(int ClientId) const
Expand Down Expand Up @@ -3968,10 +3969,9 @@ CServer *CreateServer() { return new CServer(); }

void CServer::GetClientAddr(int ClientId, NETADDR *pAddr) const
{
if(ClientId >= 0 && ClientId < MAX_CLIENTS && m_aClients[ClientId].m_State == CClient::STATE_INGAME)
{
*pAddr = *m_NetServer.ClientAddr(ClientId);
}
dbg_assert(ClientId >= 0 && ClientId < MAX_CLIENTS, "ClientId is not valid");
dbg_assert(m_aClients[ClientId].m_State != CServer::CClient::STATE_EMPTY, "Client slot is empty");
*pAddr = *m_NetServer.ClientAddr(ClientId);
}

void CServer::ReadAnnouncementsFile()
Expand Down

0 comments on commit 85e246e

Please sign in to comment.