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

This commit is contained in:
Sylvain authored and Sam Lantinga committed 2023-12-23 12:55:21 -08:00
1 parent 199f7cc3b1
commit 312f98c2a1
1 file changed
+2
+2
View File
@@ -1282,12 +1282,14 @@ static int SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char
} else if (bGameButton) { } else if (bGameButton) {
if (i >= sizeof(szGameButton)) { if (i >= sizeof(szGameButton)) {
szGameButton[sizeof(szGameButton) - 1] = '\0';
return SDL_SetError("Button name too large: %s", szGameButton); return SDL_SetError("Button name too large: %s", szGameButton);
} }
szGameButton[i] = *pchPos; szGameButton[i] = *pchPos;
i++; i++;
} else { } else {
if (i >= sizeof(szJoystickButton)) { if (i >= sizeof(szJoystickButton)) {
szJoystickButton[sizeof(szJoystickButton) - 1] = '\0';
return SDL_SetError("Joystick button name too large: %s", szJoystickButton); return SDL_SetError("Joystick button name too large: %s", szJoystickButton);
} }
szJoystickButton[i] = *pchPos; szJoystickButton[i] = *pchPos;