[gtk+] wayland: Protect against invalid keymaps gotten from the compositor



commit 8f2d8dfa3b3069c48b1c7cc82700e607d5c84e4e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 25 15:55:22 2014 +0200

    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

 gdk/wayland/gdkkeys-wayland.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gdk/wayland/gdkkeys-wayland.c b/gdk/wayland/gdkkeys-wayland.c
index 4e8e739..d734144 100644
--- a/gdk/wayland/gdkkeys-wayland.c
+++ b/gdk/wayland/gdkkeys-wayland.c
@@ -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);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]