From f8ca16c50e07a0cecda22cf04ad812563b6b8676 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Thu, 7 Dec 2023 17:59:56 +0100 Subject: [PATCH] Use real ClientID to lookup authed state and score The variable `Id` is translated for old clients and is not guranteed to be the real id. While `m_ClientID` is the real ID. That can also be used to index the CServer::m_aClients[] array to get the authed state. closed #7599 Fixes ``` valgrind ./DDNet-Server "dbg_dummies 1" [..] 2023-12-07 18:01:33 I chat: *** 'Debug dummy 1' entered and joined the game ==75634== Conditional jump or move depends on uninitialised value(s) ==75634== at 0x2DAA83: CVariableInt::Pack(unsigned char*, int, int) (compression.cpp:17) ==75634== by 0x2DAD79: CVariableInt::Compress(void const*, int, void*, int) (compression.cpp:98) ==75634== by 0x23EC50: CServer::DoSnapshot() (server.cpp:1046) ==75634== by 0x247D2D: CServer::Run() (server.cpp:2994) ==75634== by 0x230173: main (main.cpp:193) ==75634== ==75634== Conditional jump or move depends on uninitialised value(s) ==75634== at 0x2DAAF7: CVariableInt::Pack(unsigned char*, int, int) (compression.cpp:25) ==75634== by 0x2DAD79: CVariableInt::Compress(void const*, int, void*, int) (compression.cpp:98) ==75634== by 0x23EC50: CServer::DoSnapshot() (server.cpp:1046) ==75634== by 0x247D2D: CServer::Run() (server.cpp:2994) ==75634== by 0x230173: main (main.cpp:193) ==75634== ==75634== Conditional jump or move depends on uninitialised value(s) ==75634== at 0x2DAA83: CVariableInt::Pack(unsigned char*, int, int) (compression.cpp:17) ==75634== by 0x32E812: CPacker::AddInt(int) (packer.cpp:20) ==75634== by 0x23ED51: CServer::DoSnapshot() (server.cpp:1059) ==75634== by 0x247D2D: CServer::Run() (server.cpp:2994) ==75634== by 0x230173: main (main.cpp:193) ==75634== ==75634== Conditional jump or move depends on uninitialised value(s) ==75634== at 0x2DAAF7: CVariableInt::Pack(unsigned char*, int, int) (compression.cpp:25) ==75634== by 0x32E812: CPacker::AddInt(int) (packer.cpp:20) ==75634== by 0x23ED51: CServer::DoSnapshot() (server.cpp:1059) ==75634== by 0x247D2D: CServer::Run() (server.cpp:2994) ==75634== by 0x230173: main (main.cpp:193) ==75634== ``` Which is using ID 0 as index in the m_aClients array but only ID 63 was ever initialized. --- src/game/server/player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index de3ae840e..a98192c20 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -379,7 +379,7 @@ void CPlayer::Snap(int SnappingClient) pPlayerInfo->m_PlayerFlags |= protocol7::PLAYERFLAG_ADMIN; // Times are in milliseconds for 0.7 - pPlayerInfo->m_Score = m_Score.has_value() ? GameServer()->Score()->PlayerData(id)->m_BestTime * 1000 : -1; + pPlayerInfo->m_Score = m_Score.has_value() ? GameServer()->Score()->PlayerData(m_ClientID)->m_BestTime * 1000 : -1; pPlayerInfo->m_Latency = Latency; } @@ -412,7 +412,7 @@ void CPlayer::Snap(int SnappingClient) if(!pDDNetPlayer) return; - pDDNetPlayer->m_AuthLevel = Server()->GetAuthedState(id); + pDDNetPlayer->m_AuthLevel = Server()->GetAuthedState(m_ClientID); pDDNetPlayer->m_Flags = 0; if(m_Afk) pDDNetPlayer->m_Flags |= EXPLAYERFLAG_AFK;