1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01:00

Validate identifiers obtained from the server before using them.

Prevent aout_of_range exceptions from leaking to the script in case the server returns a negative identifier. Thus, resulting in a server crash since Squirrel would not know how to handle them.
This commit is contained in:
Sandu Liviu Catalin 2016-06-14 02:34:04 +03:00
parent 4327eaf72c
commit 5a225a70b9

View File

@ -886,8 +886,16 @@ Object & CPlayer::GetVehicle() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return Core::Get().GetVehicle(_Func->GetPlayerVehicleId(m_ID)).mObj;
// Retrieve the identifier of the vehicle
const Int32 id = _Func->GetPlayerVehicleId(m_ID);
// Validate the obtained identifier
if (VALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
// Return the requested information
return Core::Get().GetVehicle(id).mObj;
}
// Default to a null object
return NullObject();
}
// ------------------------------------------------------------------------------------------------
@ -1070,8 +1078,16 @@ Object & CPlayer::StandingOnVehicle() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return Core::Get().GetVehicle(_Func->GetPlayerStandingOnVehicle(m_ID)).mObj;
// Retrieve the identifier of the vehicle
const Int32 id = _Func->GetPlayerStandingOnVehicle(m_ID);
// Validate the obtained identifier
if (VALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
{
// Return the requested information
return Core::Get().GetVehicle(id).mObj;
}
// Default to a null object
return NullObject();
}
// ------------------------------------------------------------------------------------------------
@ -1079,8 +1095,16 @@ Object & CPlayer::StandingOnObject() const
{
// Validate the managed identifier
Validate();
// Return the requested information
return Core::Get().GetObject(_Func->GetPlayerStandingOnObject(m_ID)).mObj;
// Retrieve the identifier of the object
const Int32 id = _Func->GetPlayerStandingOnObject(m_ID);
// Validate the obtained identifier
if (VALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
{
// Return the requested information
return Core::Get().GetObject(id).mObj;
}
// Default to a null object
return NullObject();
}
// ------------------------------------------------------------------------------------------------