Skip to content

Commit

Permalink
fix(gamestate/server): add array bounds checks and fix native declara…
Browse files Browse the repository at this point in the history
…tions

This missed a couple of array bounds checks and a missing parameter in the native decl. of "GET_VEHICLE_DOOR_STATUS".
  • Loading branch information
tens0rfl0w committed Nov 11, 2024
1 parent 675069c commit 607f42a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
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 @@ -718,7 +724,12 @@ static void Init()

if (!wheelsFine && context.GetArgumentCount() > 1)
{
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, 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.

0 comments on commit 607f42a

Please sign in to comment.