From 3fa3c58c8b74dfe8463934ccca95c7703a9cb2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 9 Nov 2020 19:59:12 +0100 Subject: [PATCH] =?UTF-8?q?input:=20ignore=20keymap=20if=20we=20don?= =?UTF-8?q?=E2=80=99t=20recognize=20its=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/input.c b/input.c index 60780dc9..5d21a3bc 100644 --- a/input.c +++ b/input.c @@ -446,15 +446,9 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, struct seat *seat = data; struct wayland *wayl = seat->wayl; - char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); - if (map_str == MAP_FAILED) { - LOG_ERRNO("failed to mmap keyboard keymap"); - close(fd); - return; - } - - while (map_str[size - 1] == '\0') - size--; + /* + * Free old keymap state + */ if (seat->kbd.xkb_compose_state != NULL) { xkb_compose_state_unref(seat->kbd.xkb_compose_state); @@ -487,6 +481,29 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, tll_free(seat->mouse.bindings); + /* Verify keymap is in a format we understand */ + switch ((enum wl_keyboard_keymap_format)format) { + case WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP: + return; + + case WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1: + break; + + default: + LOG_WARN("unrecognized keymap format: %u", format); + return; + } + + char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + if (map_str == MAP_FAILED) { + LOG_ERRNO("failed to mmap keyboard keymap"); + close(fd); + return; + } + + while (map_str[size - 1] == '\0') + size--; + seat->kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (seat->kbd.xkb != NULL) {