Skip to content

Commit d28437d

Browse files
committed
SDL_keyboard.c: Add bounds guards when assigning to the scancode array.
Based on a patch by Jochen Schäfer <[email protected]> : On a T420 pressing the ACPI button for volume control, big scancodes were emitted. This was causing an overflow, because missing guards.
1 parent eb15b4e commit d28437d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/events/SDL_keyboard.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ SDL_SetKeymap(int start, SDL_Keycode * keys, int length)
605605
void
606606
SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
607607
{
608+
if (scancode >= SDL_NUM_SCANCODES) {
609+
return;
610+
}
608611
SDL_scancode_names[scancode] = name;
609612
}
610613

@@ -675,7 +678,7 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
675678
Uint32 type;
676679
Uint8 repeat = SDL_FALSE;
677680

678-
if (scancode == SDL_SCANCODE_UNKNOWN) {
681+
if (scancode == SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
679682
return 0;
680683
}
681684

@@ -800,7 +803,7 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
800803
allowing the user to escape the application */
801804
SDL_MinimizeWindow(keyboard->focus);
802805
}
803-
806+
804807
return (posted);
805808
}
806809

0 commit comments

Comments
 (0)