From fb0c3040c02f5413869d9187a30faf7f9481c94b Mon Sep 17 00:00:00 2001
From: Joan Bruguera <[EMAIL REDACTED]>
Date: Sat, 8 Jan 2022 21:10:14 +0100
Subject: [PATCH] wayland: Avoid infinite loop in keyboard_repeat_handle
If `repeat_info->next_repeat_ms` overflows, many key presses will be generated.
In the worst case, `now = 0xFFFFFFFFU` and the loop will never terminate.
Rearrange the comparison in order to gracefully handle the overflow case.
Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
---
src/video/wayland/SDL_waylandevents.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 551943fc996..956d5af3ee7 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -210,7 +210,7 @@ keyboard_repeat_handle(SDL_WaylandKeyboardRepeat* repeat_info, uint32_t now)
if (!repeat_info->is_key_down || !repeat_info->is_initialized) {
return ret;
}
- while (repeat_info->next_repeat_ms <= now) {
+ while ((now - repeat_info->next_repeat_ms) < 0x80000000U) {
if (repeat_info->scancode != SDL_SCANCODE_UNKNOWN) {
SDL_SendKeyboardKey(SDL_PRESSED, repeat_info->scancode);
}