Browse Source

Make sure the string is terminated, fixed invalid read in SDL_PrivateParseGamepadConfigString()

Sylvain 1 year ago
parent
commit
312f98c2a1
1 changed files with 2 additions and 0 deletions
  1. 2 0
      src/joystick/SDL_gamepad.c

+ 2 - 0
src/joystick/SDL_gamepad.c

@@ -1282,12 +1282,14 @@ static int SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char
 
         } else if (bGameButton) {
             if (i >= sizeof(szGameButton)) {
+                szGameButton[sizeof(szGameButton) - 1] = '\0';
                 return SDL_SetError("Button name too large: %s", szGameButton);
             }
             szGameButton[i] = *pchPos;
             i++;
         } else {
             if (i >= sizeof(szJoystickButton)) {
+                szJoystickButton[sizeof(szJoystickButton) - 1] = '\0';
                 return SDL_SetError("Joystick button name too large: %s", szJoystickButton);
             }
             szJoystickButton[i] = *pchPos;