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:
@ -487,6 +487,7 @@ _gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
|
|||||||
{
|
{
|
||||||
GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
|
GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
|
||||||
struct xkb_context *context;
|
struct xkb_context *context;
|
||||||
|
struct xkb_keymap *xkb_keymap;
|
||||||
char *map_str;
|
char *map_str;
|
||||||
|
|
||||||
context = xkb_context_new (0);
|
context = xkb_context_new (0);
|
||||||
@ -498,11 +499,20 @@ _gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xkb_keymap_unref (keymap_wayland->xkb_keymap);
|
xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
|
||||||
keymap_wayland->xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
|
|
||||||
munmap (map_str, size);
|
munmap (map_str, size);
|
||||||
close (fd);
|
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);
|
xkb_state_unref (keymap_wayland->xkb_state);
|
||||||
keymap_wayland->xkb_state = xkb_state_new (keymap_wayland->xkb_keymap);
|
keymap_wayland->xkb_state = xkb_state_new (keymap_wayland->xkb_keymap);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user