Commit 55882e43c4442e9a1a7a7df9cc83849c6e5f232b

Sam Lantinga 2022-08-09T00:19:02

Fixed invalid read when SDL_GameControllerSetPlayerIndex() is passed a negative player_index

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 0d778a7..94217cc 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -186,7 +186,7 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id)
         SDL_joystick_players = new_players;
         SDL_memset(&SDL_joystick_players[SDL_joystick_player_count], 0xFF, (player_index - SDL_joystick_player_count + 1) * sizeof(SDL_joystick_players[0]));
         SDL_joystick_player_count = player_index + 1;
-    } else if (SDL_joystick_players[player_index] == instance_id) {
+    } else if (player_index >= 0 && SDL_joystick_players[player_index] == instance_id) {
         /* Joystick is already assigned the requested player index */
         return SDL_TRUE;
     }