From 25d6b2b069c4d0557a0a621374691c1db3fa0a9f Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 15 Apr 2023 03:36:04 +0300 Subject: [PATCH] engine: client: fix FlushEntityPacket message overflow on legacy servers --- engine/client/cl_frame.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index 32ed990e..6715d0a6 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -654,6 +654,24 @@ FRAME PARSING ========================================================================= */ +static qboolean CL_ParseEntityNumFromPacket( sizebuf_t *msg, int *newnum ) +{ + if( cls.legacymode ) + { + *newnum = MSG_ReadWord( msg ); + if( *newnum == 0 ) + return false; + } + else + { + *newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS ); + if( *newnum == LAST_EDICT ) + return false; + } + + return true; +} + /* ================= CL_FlushEntityPacket @@ -674,8 +692,8 @@ void CL_FlushEntityPacket( sizebuf_t *msg ) // read it all, but ignore it while( 1 ) { - newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS ); - if( newnum == LAST_EDICT ) break; // done + if( !CL_ParseEntityNumFromPacket( msg, &newnum )) + break; // done if( MSG_CheckOverflow( msg )) Host_Error( "CL_FlushEntityPacket: overflow\n" ); @@ -847,21 +865,12 @@ int CL_ParsePacketEntities( sizebuf_t *msg, qboolean delta ) while( 1 ) { - int lastedict; - if( cls.legacymode ) - { - newnum = MSG_ReadWord( msg ); - lastedict = 0; - } - else - { - newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS ); - lastedict = LAST_EDICT; - } + if( !CL_ParseEntityNumFromPacket( msg, &newnum )) + break; // done - if( newnum == lastedict ) break; // end of packet entities if( MSG_CheckOverflow( msg )) Host_Error( "CL_ParsePacketEntities: overflow\n" ); + player = CL_IsPlayerIndex( newnum ); while( oldnum < newnum )