From 777628e7616f321709cc43c64c2ce0c79afced6b Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Fri, 7 Jan 2022 23:28:02 +0100 Subject: wayland: use `xkb_keymap_new_from_buffer` Instead of `xkb_keymap_new_from_string`. The protocol does not require the keymap to be null terminated and if the size of the keymap is a multiple of the page size, using `_from_string` could lead to problems. Some compositors include a null byte and even include the null byte in `size`. Therefore we have to use `strnlen` to find the real length of the string. Note that `_from_string` internally uses `strlen` and then calls `_from_buffer`. --- video/out/wayland_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 226c94f7bc..ae657ec952 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -350,7 +350,8 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard, return; } - wl->xkb_keymap = xkb_keymap_new_from_string(wl->xkb_context, map_str, + wl->xkb_keymap = xkb_keymap_new_from_buffer(wl->xkb_context, map_str, + strnlen(map_str, size), XKB_KEYMAP_FORMAT_TEXT_V1, 0); munmap(map_str, size); -- cgit v1.2.3