Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gamestate/server): add array bounds checks and fix native decl. #2923

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ struct CVehicleGameStateNodeData
bool sirenOn;
int lockStatus;
int doorsOpen;
int doorPositions[1 << 7];
int doorPositions[7];
bool isStationary;
bool lightsOn;
bool highbeamsOn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,13 @@ static void Init()

if (context.GetArgumentCount() > 1 && doorsOpen)
{
doorStatus = vn->doorPositions[context.GetArgument<int>(1)];
const int index = context.GetArgument<int>(1);
if (index < 0 || index > 6)
{
return doorStatus;
}

doorStatus = vn->doorPositions[index];
}

return doorStatus;
Expand Down Expand Up @@ -716,9 +722,14 @@ static void Init()
bool tyreBurst = false;
bool wheelsFine = vn->tyresFine;

if (!wheelsFine && context.GetArgumentCount() > 1)
if (!wheelsFine)
{
int tyreID = context.GetArgument<int>(1);
const int tyreID = context.GetArgument<int>(1);
if (tyreID < 0 || tyreID > 15)
{
return tyreBurst;
}

bool completely = context.GetArgument<bool>(2);

int tyreStatus = vn->tyreStatus[tyreID];
Expand Down Expand Up @@ -1219,7 +1230,11 @@ static void Init()
{
auto vn = entity->syncTree->GetVehicleGameState();

int seatArg = context.GetArgument<int>(1) + 2;
const int seatArg = context.GetArgument<int>(1) + 2;
if (seatArg < 0 || seatArg > 31)
{
return 0;
}

// get the current resource manager
auto resourceManager = fx::ResourceManager::GetCurrent();
Expand Down Expand Up @@ -1248,7 +1263,11 @@ static void Init()
{
auto vn = entity->syncTree->GetVehicleGameState();

int seatArg = context.GetArgument<int>(1) + 2;
const int seatArg = context.GetArgument<int>(1) + 2;
if (seatArg < 0 || seatArg > 31)
{
return 0;
}

// get the current resource manager
auto resourceManager = fx::ResourceManager::GetCurrent();
Expand Down
6 changes: 4 additions & 2 deletions ext/native-decls/GetVehicleDoorStatus.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ apiset: server
## GET_VEHICLE_DOOR_STATUS

```c
int GET_VEHICLE_DOOR_STATUS(Vehicle vehicle);
int GET_VEHICLE_DOOR_STATUS(Vehicle vehicle, cs_split int doorIndex);
```
Returns the open position of the specified door on the target vehicle.
## Parameters
* **vehicle**:
- **vehicle**: The target vehicle.
- **doorIndex**: Index of door to check (0-6).
## Return value
A number from 0 to 7.
Loading