From 2b1edf4113750745b707d3376664abfa647c6cee Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 4 Jan 2020 11:05:06 -0800 Subject: [PATCH] X11_InitKeyboard: do not call XAutoRepeatOn unnecessarily Use XGetKeyboardControl to initialize the current XKeyboardState, and skip XAutoRepeatOn invocation if global_auto_repeat is AutoRepeatModeOn. This fixes SDL2 when the X11 client is untrusted. --- src/video/x11/SDL_x11keyboard.c | 5 ++++- src/video/x11/SDL_x11sym.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index 9ca703c4c..87f7c5542 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -267,8 +267,11 @@ X11_InitKeyboard(_THIS) int best_index; int distance; Bool xkb_repeat = 0; + XKeyboardState values = { .global_auto_repeat = AutoRepeatModeOff }; - X11_XAutoRepeatOn(data->display); + X11_XGetKeyboardControl(data->display, &values); + if (values.global_auto_repeat != AutoRepeatModeOn) + X11_XAutoRepeatOn(data->display); #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM { diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h index 841031285..90fa49092 100644 --- a/src/video/x11/SDL_x11sym.h +++ b/src/video/x11/SDL_x11sym.h @@ -72,6 +72,7 @@ SDL_X11_SYM(char*,XGetAtomName,(Display *a,Atom b),(a,b),return) SDL_X11_SYM(int,XGetInputFocus,(Display *a,Window *b,int *c),(a,b,c),return) SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return) SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return) +SDL_X11_SYM(int,XGetKeyboardControl,(Display* a, XKeyboardState* b),(a,b),return) SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return) SDL_X11_SYM(Window,XGetSelectionOwner,(Display* a,Atom b),(a,b),return) SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)