mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 19:00:08 +00:00
wayland: Protect against invalid keymaps gotten from the compositor
If the compositor sends a keymap that fails on "compilation", xkb_keymap_new_from_string() returns NULL, which makes xkb_state_new() crash when assuming there is a keymap. In these cases, gdk must remain with a xkb_state to handle modifiers/keys properly, so warn about the invalid keymap string, and keep the previous keymap (currently initialized to "us") https://bugzilla.gnome.org/show_bug.cgi?id=735389
This commit is contained in:
parent
ab6f771413
commit
8f2d8dfa3b
@ -487,6 +487,7 @@ _gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
|
||||
{
|
||||
GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
|
||||
struct xkb_context *context;
|
||||
struct xkb_keymap *xkb_keymap;
|
||||
char *map_str;
|
||||
|
||||
context = xkb_context_new (0);
|
||||
@ -498,11 +499,20 @@ _gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
|
||||
return;
|
||||
}
|
||||
|
||||
xkb_keymap_unref (keymap_wayland->xkb_keymap);
|
||||
keymap_wayland->xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
|
||||
xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
|
||||
munmap (map_str, size);
|
||||
close (fd);
|
||||
|
||||
if (!xkb_keymap)
|
||||
{
|
||||
g_warning ("Got invalid keymap from compositor, keeping previous/default one");
|
||||
xkb_context_unref (context);
|
||||
return;
|
||||
}
|
||||
|
||||
xkb_keymap_unref (keymap_wayland->xkb_keymap);
|
||||
keymap_wayland->xkb_keymap = xkb_keymap;
|
||||
|
||||
xkb_state_unref (keymap_wayland->xkb_state);
|
||||
keymap_wayland->xkb_state = xkb_state_new (keymap_wayland->xkb_keymap);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user