From 6f8fffc275039025f02ade52f4a0fe5c9783cbdc Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 9 Apr 2023 19:38:05 -0300 Subject: [PATCH] qt: Fix potential UAF and leak in Wayland xkbcommon keyboard --- src/qt/xkbcommon_wl_keyboard.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qt/xkbcommon_wl_keyboard.cpp b/src/qt/xkbcommon_wl_keyboard.cpp index c6736f2d4..4db4971ee 100644 --- a/src/qt/xkbcommon_wl_keyboard.cpp +++ b/src/qt/xkbcommon_wl_keyboard.cpp @@ -70,15 +70,20 @@ kbd_keymap(void *data, struct wl_keyboard *wl_kbd, uint32_t format, return; } + if (seat->keymap) { + static struct xkb_keymap *keymap = seat->keymap; + seat->keymap = NULL; + xkbcommon_wl_set_keymap(); + xkb_keymap_unref(keymap); + } + seat->keymap = xkb_keymap_new_from_buffer(ctx, buf, size - 1, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(buf, size); close(fd); - if (!seat->keymap) { + if (!seat->keymap) qWarning() << "XKB Keyboard: Keymap compilation failed"; - return; - } xkbcommon_wl_set_keymap(); }