mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #590 from Redix/pr_finish_buffer
Fix buffer overflow in race recorder and ghost
This commit is contained in:
commit
7296dd2b53
|
@ -554,25 +554,18 @@ void CGhost::OnMessage(int MsgType, void *pRawMsg)
|
|||
CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
|
||||
if(pMsg->m_ClientID == -1 && m_RaceState == RACE_STARTED)
|
||||
{
|
||||
const char* pMessage = pMsg->m_pMessage;
|
||||
|
||||
int Num = 0;
|
||||
while(str_comp_num(pMessage, " finished in: ", 14))
|
||||
{
|
||||
pMessage++;
|
||||
Num++;
|
||||
if(!pMessage[0])
|
||||
return;
|
||||
}
|
||||
|
||||
// store the name
|
||||
char aName[64];
|
||||
str_copy(aName, pMsg->m_pMessage, Num+1);
|
||||
char aName[MAX_NAME_LENGTH];
|
||||
const char *pFinished = str_find(pMsg->m_pMessage, " finished in: ");
|
||||
int FinishedPos = pFinished - pMsg->m_pMessage;
|
||||
if (!pFinished || FinishedPos == 0 || FinishedPos >= (int)sizeof(aName))
|
||||
return;
|
||||
|
||||
str_copy(aName, pMsg->m_pMessage, FinishedPos + 1);
|
||||
|
||||
// prepare values and state for saving
|
||||
int Minutes;
|
||||
float Seconds;
|
||||
if(!str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) && sscanf(pMessage, " finished in: %d minute(s) %f", &Minutes, &Seconds) == 2)
|
||||
if(!str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) && sscanf(pFinished, " finished in: %d minute(s) %f", &Minutes, &Seconds) == 2)
|
||||
{
|
||||
m_RaceState = RACE_FINISHED;
|
||||
float CurTime = Minutes*60 + Seconds;
|
||||
|
|
|
@ -112,25 +112,19 @@ void CRaceDemo::OnMessage(int MsgType, void *pRawMsg)
|
|||
CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
|
||||
if(pMsg->m_ClientID == -1 && m_RaceState == RACE_STARTED)
|
||||
{
|
||||
const char* pMessage = pMsg->m_pMessage;
|
||||
|
||||
int Num = 0;
|
||||
while(str_comp_num(pMessage, " finished in: ", 14))
|
||||
{
|
||||
pMessage++;
|
||||
Num++;
|
||||
if(!pMessage[0])
|
||||
return;
|
||||
}
|
||||
|
||||
char aName[MAX_NAME_LENGTH];
|
||||
const char *pFinished = str_find(pMsg->m_pMessage, " finished in: ");
|
||||
int FinishedPos = pFinished - pMsg->m_pMessage;
|
||||
if (!pFinished || FinishedPos == 0 || FinishedPos >= (int)sizeof(aName))
|
||||
return;
|
||||
|
||||
// store the name
|
||||
char aName[64];
|
||||
str_copy(aName, pMsg->m_pMessage, Num+1);
|
||||
str_copy(aName, pMsg->m_pMessage, FinishedPos + 1);
|
||||
|
||||
// prepare values and state for saving
|
||||
int Minutes;
|
||||
float Seconds;
|
||||
if(!str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) && sscanf(pMessage, " finished in: %d minute(s) %f", &Minutes, &Seconds) == 2)
|
||||
if(!str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) && sscanf(pFinished, " finished in: %d minute(s) %f", &Minutes, &Seconds) == 2)
|
||||
{
|
||||
m_RaceState = RACE_FINISHED;
|
||||
m_RecordStopTime = Client()->GameTick() + Client()->GameTickSpeed();
|
||||
|
|
Loading…
Reference in a new issue