From 759a15ccbbc1decfaec47b7968dd78f40f1ab66d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Apr 2020 21:01:19 +0530 Subject: [PATCH] X11: Handle invalid data being sent with drag events by some applications Fixes #2505 --- glfw/x11_window.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 7a9efbddb..3a1a8902b 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -1075,6 +1075,21 @@ static void onConfigChange(void) } } +static void +get_atom_names(Atom *atoms, int count, char **atom_names) { + _glfwGrabErrorHandlerX11(); + XGetAtomNames(_glfw.x11.display, atoms, count, atom_names); + _glfwReleaseErrorHandlerX11(); + if (_glfw.x11.errorCode != Success) { + for (int i = 0; i < count; i++) { + _glfwGrabErrorHandlerX11(); + atom_names[i] = XGetAtomName(_glfw.x11.display, atoms[i]); + _glfwReleaseErrorHandlerX11(); + if (_glfw.x11.errorCode != Success) atom_names[i] = NULL; + } + } +} + // Process the specified X event // static void processEvent(XEvent *event) @@ -1474,7 +1489,7 @@ static void processEvent(XEvent *event) } char **atom_names = calloc(count, sizeof(char**)); if (atom_names) { - XGetAtomNames(_glfw.x11.display, formats, count, atom_names); + get_atom_names(formats, count, atom_names); for (i = 0; i < count; i++) {