From 4f1c5397b65d63a8dcaa9fcaae049ab6db5d50a1 Mon Sep 17 00:00:00 2001 From: Kamay Xutax Date: Fri, 6 Sep 2024 04:56:33 +0200 Subject: [PATCH] Some improvements on possible buffer overflow ... --- game/client/cstrike/c_cs_player.cpp | 22 +++++++++++----------- game/client/prediction.cpp | 6 ++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/game/client/cstrike/c_cs_player.cpp b/game/client/cstrike/c_cs_player.cpp index 6bef0548ad..4a0d0d05ea 100644 --- a/game/client/cstrike/c_cs_player.cpp +++ b/game/client/cstrike/c_cs_player.cpp @@ -11,6 +11,7 @@ #include "cdll_client_int.h" #include "convar.h" #include "datacache/imdlcache.h" +#include "dbg.h" #include "dt_recv.h" #include "iconvar.h" #include "interpolatedvar.h" @@ -2144,12 +2145,13 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) if ( player && !player->IsLocalPlayer() ) { const auto nAttackerTickBase = event->GetInt( "tickbase" ); + const auto pStudioHdr = player->GetModelPtr(); + const auto numhitboxes = event->GetInt( "num_hitboxes" ); - const auto numhitboxes = event->GetInt( "num_hitboxes" ); QAngle angles[MAXSTUDIOBONES]; Vector positions[MAXSTUDIOBONES]; - Assert( numhitboxes == player->GetModelPtr()->numbones() ); + AssertFatal( numhitboxes == pStudioHdr->numbones() ); for ( int i = 0; i < numhitboxes; i++ ) { @@ -2210,7 +2212,7 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) event->GetFloat( "angle_z" ) ) ); const auto numposeparams = event->GetInt( "num_poseparams" ); - Assert( numposeparams == player->GetModelPtr()->GetNumPoseParameters() ); + AssertFatal( numposeparams == pStudioHdr->GetNumPoseParameters() ); for ( int i = 0; i < numposeparams; i++ ) { @@ -2221,7 +2223,7 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) } const auto numbonecontrollers = event->GetInt( "num_bonecontrollers" ); - Assert( numbonecontrollers == player->GetModelPtr()->GetNumBoneControllers() ); + AssertFatal( numbonecontrollers == pStudioHdr->GetNumBoneControllers() ); for ( int i = 0; i < numbonecontrollers; i++ ) { @@ -2232,7 +2234,7 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) } auto numanimoverlays = event->GetInt( "num_anim_overlays" ); - Assert( numanimoverlays == player->GetNumAnimOverlays() ); + AssertFatal( numanimoverlays == player->GetNumAnimOverlays() ); for ( int i = 0; i < numanimoverlays; i++ ) { @@ -2352,16 +2354,14 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) pos++; } - auto mdl = player->GetModelPtr(); - - for ( int i = 0; i < mdl->GetNumPoseParameters(); i++ ) + for ( int i = 0; i < pStudioHdr->GetNumPoseParameters(); i++ ) { if ( pRecord->m_flPoseParameters[i] != player->m_flPoseParameter[i] ) { char buffer[256]; V_sprintf_safe( buffer, "pose parameter %s (%i): %f != %f", - mdl->pPoseParameter( i ).pszName(), + pStudioHdr->pPoseParameter( i ).pszName(), i, player->m_flPoseParameter[i], pRecord->m_flPoseParameters[i] ); @@ -2371,14 +2371,14 @@ void C_CSPlayer::FireGameEvent( IGameEvent* event ) } } - for ( int i = 0; i < mdl->GetNumBoneControllers(); i++ ) + for ( int i = 0; i < pStudioHdr->GetNumBoneControllers(); i++ ) { if ( pRecord->m_flEncodedControllers[i] != player->m_flEncodedController[i] ) { char buffer[256]; V_sprintf_safe( buffer, "bone controller %i (%i): %f != %f", - mdl->pBonecontroller( i )->bone, + pStudioHdr->pBonecontroller( i )->bone, i, player->m_flEncodedController[i], pRecord->m_flEncodedControllers[i] ); diff --git a/game/client/prediction.cpp b/game/client/prediction.cpp index 6c1043bf13..c4bbde42cd 100644 --- a/game/client/prediction.cpp +++ b/game/client/prediction.cpp @@ -897,6 +897,7 @@ void CPrediction::RunPostThink( C_BasePlayer *player ) void CPrediction::CheckMovingGround( CBasePlayer *player, double frametime ) { +#if !defined( NO_ENTITY_PREDICTION ) VPROF( "CPrediction::CheckMovingGround()" ); CBaseEntity *groundentity; @@ -926,6 +927,7 @@ void CPrediction::CheckMovingGround( CBasePlayer *player, double frametime ) } player->RemoveFlag( FL_BASEVELOCITY ); +#endif } //----------------------------------------------------------------------------- @@ -1352,6 +1354,7 @@ void CPrediction::RunSimulation( int current_command, float curtime, CUserCmd *c // TODO_ENHANCED: we should get rid of this to prefer SaveData/RestoreData. void CPrediction::RestorePredictedTouched( int current_command ) { +#if !defined( NO_ENTITY_PREDICTION ) VPROF( "CPrediction::RestorePredictedTouched" ); if ( m_nCommandsPredicted == 0 ) @@ -1419,10 +1422,12 @@ void CPrediction::RestorePredictedTouched( int current_command ) g_EventQueue.AddEvent( newEvent ); } +#endif } void CPrediction::StorePredictedTouched( int current_command ) { +#if !defined( NO_ENTITY_PREDICTION ) VPROF( "CPrediction::StorePredictedTouched" ); int pc = predictables->GetPredictableCount(); @@ -1480,6 +1485,7 @@ void CPrediction::StorePredictedTouched( int current_command ) // This will be reconstructed later. g_EventQueue.Clear(); +#endif } //-----------------------------------------------------------------------------