[mutter/wip/smcv/survive-misconfigured-keymap] backends/native: Don't crash if keymap is misconfigured




commit 7a4c28a326f1bc3e2e0c7f238d179639ee799ce6
Author: Simon McVittie <smcv debian org>
Date:   Thu Nov 26 11:54:48 2020 +0000

    backends/native: Don't crash if keymap is misconfigured
    
    xkb recently gained support for user-specified keymaps, which means we
    can no longer assume that the configuration data is necessarily fully
    complete or correct; and the configuration language is quite a labyrinth,
    so it's easy to get wrong. If setting the keymap fails, leave it in
    whatever state it previously had, since that seems preferable to crashing
    with a NULL pointer dereference.
    
    Resolves: https://gitlab.gnome.org/GNOME/mutter/-/issues/1555
    Signed-off-by: Simon McVittie <smcv debian org>
    
    Gbp-Pq: Name backends-native-Don-t-crash-if-keymap-is-misconfigured.patch

 src/backends/native/meta-backend-native.c | 8 ++++++++
 src/backends/native/meta-keymap-native.c  | 2 ++
 src/backends/native/meta-seat-native.c    | 1 +
 3 files changed, 11 insertions(+)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 18709d5a58..73093cb038 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -284,6 +284,14 @@ meta_backend_native_set_keymap (MetaBackend *backend,
   keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
   xkb_context_unref (context);
 
+  if (keymap == NULL)
+    {
+      g_warning ("Unable to load configured keymap: rules=%s, model=%s, layout=%s, variant=%s, options=%s",
+                 DEFAULT_XKB_RULES_FILE, DEFAULT_XKB_MODEL, layouts,
+                 variants, options);
+      return;
+    }
+
   seat = clutter_backend_get_default_seat (clutter_backend);
   meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat), keymap);
 
diff --git a/src/backends/native/meta-keymap-native.c b/src/backends/native/meta-keymap-native.c
index f55cd059f8..3b0da0d1fa 100644
--- a/src/backends/native/meta-keymap-native.c
+++ b/src/backends/native/meta-keymap-native.c
@@ -122,6 +122,8 @@ void
 meta_keymap_native_set_keyboard_map (MetaKeymapNative  *keymap,
                                      struct xkb_keymap *xkb_keymap)
 {
+  g_return_if_fail (xkb_keymap != NULL);
+
   if (keymap->keymap)
     xkb_keymap_unref (keymap->keymap);
   keymap->keymap = xkb_keymap_ref (xkb_keymap);
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
index 3df16761a1..e2f62b09b3 100644
--- a/src/backends/native/meta-seat-native.c
+++ b/src/backends/native/meta-seat-native.c
@@ -3124,6 +3124,7 @@ meta_seat_native_set_keyboard_map (MetaSeatNative    *seat,
   ClutterKeymap *keymap;
 
   g_return_if_fail (META_IS_SEAT_NATIVE (seat));
+  g_return_if_fail (xkb_keymap != NULL);
 
   keymap = clutter_seat_get_keymap (CLUTTER_SEAT (seat));
   meta_keymap_native_set_keyboard_map (META_KEYMAP_NATIVE (keymap),


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