engine: client: validate player index and max players

This commit is contained in:
Alibek Omarov
2026-05-16 21:00:45 +05:00
parent fc4b982ecc
commit e56cf4e1da
2 changed files with 21 additions and 0 deletions

View File

@@ -891,6 +891,15 @@ static void CL_ParseServerData( sizebuf_t *msg, connprotocol_t proto )
}
}
if( cl.playernum < 0 || cl.playernum >= MAX_CLIENTS || cl.maxclients < 0 || cl.maxclients >= MAX_CLIENTS )
{
Con_Printf( S_ERROR "%s: invalid playernum or maxclients (%d and %d must be less than %d)\n", __func__,
cl.playernum, cl.maxclients, MAX_CLIENTS );
CL_Disconnect_f();
Host_AbortCurrentFrame();
return;
}
Q_snprintf( mapfile, sizeof( mapfile ), "maps/%s.bsp", clgame.mapname );
if( CRC32_MapFile( &cl.worldmapCRC, mapfile, cl.maxclients > 1 ))
{

View File

@@ -973,12 +973,21 @@ void CL_ParseQuakeMessage( sizebuf_t *msg )
break;
case svc_updatename:
param1 = MSG_ReadByte( msg );
if( param1 >= ARRAYSIZE( cl.players ))
{
MSG_ReadString( msg );
break;
}
Q_strncpy( cl.players[param1].name, MSG_ReadString( msg ), sizeof( cl.players[0].name ));
Q_strncpy( cl.players[param1].model, "player", sizeof( cl.players[0].name ));
break;
case svc_updatefrags:
param1 = MSG_ReadByte( msg );
param2 = MSG_ReadShort( msg );
if( param1 >= ARRAYSIZE( cl.players ))
break;
// HACKHACK: store frags into spectator
cl.players[param1].spectator = param2;
break;
@@ -994,6 +1003,9 @@ void CL_ParseQuakeMessage( sizebuf_t *msg )
case svc_updatecolors:
param1 = MSG_ReadByte( msg );
param2 = MSG_ReadByte( msg );
if( param1 >= ARRAYSIZE( cl.players ) || param2 >= ARRAYSIZE( cl.players ))
break;
cl.players[param1].topcolor = param2 & 0xF;
cl.players[param1].bottomcolor = (param2 & 0xF0) >> 4;
break;