From efa3c5451169f00e5f08adfc5d1f1ca094d06814 Mon Sep 17 00:00:00 2001 From: saml1er Date: Sat, 15 Dec 2018 06:02:15 +0500 Subject: [PATCH] Add sanity checks for pool function calls --- Client/game_sa/CPoolsSA.cpp | 2 - Client/mods/deathmatch/logic/CClientGame.cpp | 60 +++++++++++++++---- .../mods/deathmatch/logic/CClientVehicle.cpp | 8 +-- Client/multiplayer_sa/CMultiplayerSA_1.3.cpp | 11 ++-- .../multiplayer_sa/multiplayer_shotsync.cpp | 4 +- 5 files changed, 63 insertions(+), 22 deletions(-) diff --git a/Client/game_sa/CPoolsSA.cpp b/Client/game_sa/CPoolsSA.cpp index d5340d1547..8f09e01b2b 100644 --- a/Client/game_sa/CPoolsSA.cpp +++ b/Client/game_sa/CPoolsSA.cpp @@ -183,8 +183,6 @@ SClientEntity* CPoolsSA::GetVehicle(DWORD* pGameInterface) { DEBUG_TRACE("SClientEntity* CPoolsSA::GetVehicle ( DWORD* pGameInterface )"); - assert(pGameInterface); - if (m_bGetVehicleEnabled) { CVehicleSAInterface* pInterface = reinterpret_cast(pGameInterface); diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 9b2b899a28..13ee1a0d87 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -4561,10 +4561,14 @@ bool CClientGame::VehicleCollisionHandler(CVehicleSAInterface*& pCollidingVehicl { CPools* pPools = g_pGame->GetPools(); SClientEntity* pColliderEntity = pPools->GetVehicle((DWORD*)pCollidingVehicle); - ; if (pColliderEntity) { - CClientEntity* pVehicleClientEntity = pColliderEntity->pClientEntity; + CClientEntity* pVehicleClientEntity = pColliderEntity->pClientEntity; + if (!pVehicleClientEntity) + { + return false; + } + CClientVehicle* pClientVehicle = static_cast(pVehicleClientEntity); CClientEntity* pCollidedWithClientEntity = pPools->GetClientEntity((DWORD*)pCollidedWith); @@ -4644,8 +4648,12 @@ bool CClientGame::HeliKillHandler(CVehicleSAInterface* pHeliInterface, CEntitySA SClientEntity* pVehicleEntity = pPools->GetVehicle((DWORD*)pHeliInterface); if (pVehicleEntity) { - CVehicle* pHeli = reinterpret_cast(pVehicleEntity->pEntity); CClientVehicle* pClientHeli = reinterpret_cast(pVehicleEntity->pClientEntity); + if (!pClientHeli) + { + return true; + } + if (!pClientHeli->AreHeliBladeCollisionsEnabled()) { return false; @@ -4654,8 +4662,11 @@ bool CClientGame::HeliKillHandler(CVehicleSAInterface* pHeliInterface, CEntitySA SClientEntity* pPedEntity = pPools->GetPed((DWORD*)pHitInterface); if (pPedEntity) { - CPed* pPed = reinterpret_cast(pPedEntity->pEntity); CClientPed* pClientPed = reinterpret_cast(pPedEntity->pClientEntity); + if (!pClientPed) + { + return false; + } // Iterate our "stored" cancel state and find the heli in question std::pair::iterator, std::multimap::iterator> iterators = @@ -4714,7 +4725,12 @@ bool CClientGame::VehicleDamageHandler(CEntitySAInterface* pVehicleInterface, fl if (pVehicleEntity) { CClientVehicle* pClientVehicle = reinterpret_cast(pVehicleEntity->pClientEntity); - CClientEntity* pClientAttacker = pPools->GetClientEntity((DWORD*)pAttackerInterface); + if (!pClientVehicle) + { + return bAllowDamage; + } + + CClientEntity* pClientAttacker = pPools->GetClientEntity((DWORD*)pAttackerInterface); // Compose arguments // attacker, weapon, loss, damagepos, tyreIdx @@ -4754,6 +4770,10 @@ bool CClientGame::ObjectDamageHandler(CObjectSAInterface* pObjectInterface, floa if (pObjectEntity) { CClientObject* pClientObject = reinterpret_cast(pObjectEntity->pClientEntity); + if (!pClientObject) + { + return true; + } CLuaArguments Arguments; Arguments.PushNumber(fLoss); @@ -4778,6 +4798,11 @@ bool CClientGame::ObjectBreakHandler(CObjectSAInterface* pObjectInterface, CEnti if (pObjectEntity) { CClientObject* pClientObject = reinterpret_cast(pObjectEntity->pClientEntity); + if (!pClientObject) + { + return true; + } + if (!pClientObject->IsBreakable(false)) return false; @@ -4808,13 +4833,21 @@ bool CClientGame::WaterCannonHitHandler(CVehicleSAInterface* pCannonVehicle, CPe { CLuaArguments Arguments; - CClientVehicle* pCannonClientVehicle = reinterpret_cast(pVehicleEntity->pClientEntity); + CClientVehicle* pCannonClientVehicle = reinterpret_cast(pVehicleEntity->pClientEntity); + if (!pCannonClientVehicle) + { + return false; + } + CClientPed* pClientPed = nullptr; SClientEntity* pPedEntity = pPools->GetPed((DWORD*)pHitPed); if (pPedEntity) { pClientPed = reinterpret_cast(pPedEntity->pClientEntity); - Arguments.PushElement(pClientPed); + if (pClientPed) + { + Arguments.PushElement(pClientPed); + } } else { @@ -4823,7 +4856,7 @@ bool CClientGame::WaterCannonHitHandler(CVehicleSAInterface* pCannonVehicle, CPe // Trigger our event bool bContinue = true; - if (!IS_PLAYER(pClientPed)) + if (pClientPed && !IS_PLAYER(pClientPed)) bContinue = pCannonClientVehicle->CallEvent("onClientPedHitByWaterCannon", Arguments, true); else bContinue = pCannonClientVehicle->CallEvent("onClientPlayerHitByWaterCannon", Arguments, true); @@ -4844,8 +4877,11 @@ bool CClientGame::VehicleFellThroughMapHandler(CVehicleSAInterface* pVehicleInte if (pVehicleEntity) { CClientVehicle* pClientVehicle = reinterpret_cast(pVehicleEntity->pClientEntity); - // handle or don't - return pClientVehicle->OnVehicleFallThroughMap(); + if (pClientVehicle) + { + // handle or don't + return pClientVehicle->OnVehicleFallThroughMap(); + } } } // unhandled @@ -5309,6 +5345,10 @@ void CClientGame::BulletImpact(CPed* pInitiator, CEntity* pVictim, const CVector { // Find the client ped that initiated the bullet impact CClientPed* pInitiatorPed = reinterpret_cast(pPedEntity->pClientEntity); + if (!pInitiatorPed) + { + return; + } // Calculate the collision of the bullet CVector vecCollision; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index d9281a918a..cddf4ebbc7 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -1930,7 +1930,7 @@ CClientVehicle* CClientVehicle::GetPreviousTrainCarriage(void) CPools* pPools = g_pGame->GetPools(); CEntitySAInterface* pInterface = pPreviousTrainCarriage->GetInterface(); SClientEntity* pVehicleClientEntity = pPools->GetVehicle((DWORD*)pInterface); - if (pVehicleClientEntity) + if (pVehicleClientEntity && pVehicleClientEntity->pClientEntity) { return reinterpret_cast(pVehicleClientEntity->pClientEntity); } @@ -1952,7 +1952,7 @@ CClientVehicle* CClientVehicle::GetNextTrainCarriage(void) CPools* pPools = g_pGame->GetPools(); CEntitySAInterface* pInterface = pNextTrainCarriage->GetInterface(); SClientEntity* pVehicleClientEntity = pPools->GetVehicle((DWORD*)pInterface); - if (pVehicleClientEntity) + if (pVehicleClientEntity && pVehicleClientEntity->pClientEntity) { return reinterpret_cast(pVehicleClientEntity->pClientEntity); } @@ -3052,7 +3052,7 @@ CClientVehicle* CClientVehicle::GetTowedVehicle(void) { CPools* pPools = g_pGame->GetPools(); SClientEntity* pVehicleEntity = pPools->GetVehicle((DWORD*)pGameVehicle->GetInterface()); - if (pVehicleEntity) + if (pVehicleEntity && pVehicleEntity->pClientEntity) { return reinterpret_cast(pVehicleEntity->pClientEntity); } @@ -3071,7 +3071,7 @@ CClientVehicle* CClientVehicle::GetRealTowedVehicle(void) { CPools* pPools = g_pGame->GetPools(); SClientEntity* pVehicleEntity = pPools->GetVehicle((DWORD*)pGameVehicle->GetInterface()); - if (pVehicleEntity) + if (pVehicleEntity && pVehicleEntity->pClientEntity) { return reinterpret_cast(pVehicleEntity->pClientEntity); } diff --git a/Client/multiplayer_sa/CMultiplayerSA_1.3.cpp b/Client/multiplayer_sa/CMultiplayerSA_1.3.cpp index ccd3ad7471..b05eea84de 100644 --- a/Client/multiplayer_sa/CMultiplayerSA_1.3.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA_1.3.cpp @@ -825,11 +825,14 @@ bool SirenCheckCameraPosition() { SClientEntity* pVehicleClientEntity = pGameInterface->GetPools()->GetVehicle((DWORD*)pVehicleWithTheSiren); CVehicle* pVehicle = pVehicleClientEntity ? pVehicleClientEntity->pEntity : nullptr; - // Do we have sirens given by us and is the 360 flag set? - if (pVehicle->DoesVehicleHaveSirens() && pVehicle->IsSiren360EffectEnabled()) + if (pVehicle) { - // Do 360 code - return true; + // Do we have sirens given by us and is the 360 flag set? + if (pVehicle->DoesVehicleHaveSirens() && pVehicle->IsSiren360EffectEnabled()) + { + // Do 360 code + return true; + } } } // Only visible from the front diff --git a/Client/multiplayer_sa/multiplayer_shotsync.cpp b/Client/multiplayer_sa/multiplayer_shotsync.cpp index b93f6c42ef..f6bb317fa6 100644 --- a/Client/multiplayer_sa/multiplayer_shotsync.cpp +++ b/Client/multiplayer_sa/multiplayer_shotsync.cpp @@ -1160,7 +1160,7 @@ void OnMy_CWeapon_FireInstantHit_Mid(CEntitySAInterface* pEntity, CVector* pvecN { SClientEntity* pPedClientEntity = m_pools->GetPed((DWORD*)pEntity); CPed* pTargetingPed = pPedClientEntity ? pPedClientEntity->pEntity : nullptr; - if (IsLocalPlayer(pTargetingPed)) + if (pTargetingPed && IsLocalPlayer(pTargetingPed)) { CVector vecEnd = *pvecEnd; CVector vecStart = *pvecAimedStart; @@ -1246,7 +1246,7 @@ void OnMy_CWeapon_FireSniper_Mid(CEntitySAInterface* pEntity, CVector* pvecEndHi { SClientEntity* pPedClientEntity = m_pools->GetPed((DWORD*)pEntity); CPed* pTargetingPed = pPedClientEntity ? pPedClientEntity->pEntity : nullptr; - if (IsLocalPlayer(pTargetingPed)) + if (pTargetingPed && IsLocalPlayer(pTargetingPed)) { CVector vecEnd = *pvecEndMaxRange; CVector vecStart = *pvecStart;