mirror of
https://github.com/raysan5/raylib.git
synced 2026-06-28 14:00:29 +00:00
[rcore] Bounds-check gamepad index in GetGamepadAxisCount() and GetGamepadName() (#5937)
* [rcore] Bounds-check gamepad index in GetGamepadAxisCount() and GetGamepadName() Both public getters indexed CORE.Input.Gamepad.axisCount[gamepad] / .name[gamepad] with an unvalidated gamepad argument -- an out-of-bounds read for gamepad < 0 or gamepad >= MAX_GAMEPADS. Every sibling gamepad accessor (IsGamepadAvailable, IsGamepadButton*, GetGamepadAxisMovement) already guards the index; add the same check, returning a safe default (0 / NULL). * Refactor GetGamepadName/GetGamepadAxisCount to single-return pattern --------- Co-authored-by: Brandon Arrendondo <brandon.arrendondo@bissell.com>
This commit is contained in:
committed by
GitHub
parent
9215540015
commit
3edfe19438
12
src/rcore.c
12
src/rcore.c
@@ -3934,7 +3934,11 @@ bool IsGamepadAvailable(int gamepad)
|
||||
// Get gamepad internal name id
|
||||
const char *GetGamepadName(int gamepad)
|
||||
{
|
||||
return CORE.Input.Gamepad.name[gamepad];
|
||||
const char *name = NULL;
|
||||
|
||||
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS)) name = CORE.Input.Gamepad.name[gamepad];
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
// Check if gamepad button has been pressed once
|
||||
@@ -3999,7 +4003,11 @@ int GetGamepadButtonPressed(void)
|
||||
// Get gamepad axis count
|
||||
int GetGamepadAxisCount(int gamepad)
|
||||
{
|
||||
return CORE.Input.Gamepad.axisCount[gamepad];
|
||||
int result = 0;
|
||||
|
||||
if ((gamepad >= 0) && (gamepad < MAX_GAMEPADS)) result = CORE.Input.Gamepad.axisCount[gamepad];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get axis movement vector for a gamepad
|
||||
|
||||
Reference in New Issue
Block a user