Commit 8be2608a264f97c504d85e9481a6c1019209d6ed

Ran Benita 2014-02-09T18:02:11

x11: don't trust keycode before testing its range The assert is not very useful access the key just before. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/x11/keymap.c b/src/x11/keymap.c
index 4c6b29c..57f2412 100644
--- a/src/x11/keymap.c
+++ b/src/x11/keymap.c
@@ -536,11 +536,13 @@ get_explicits(struct xkb_keymap *keymap, xcb_connection_t *conn,
 
     for (int i = 0; i < length; i++) {
         xcb_xkb_set_explicit_t *wire = iter.data;
-        struct xkb_key *key = &keymap->keys[wire->keycode];
+        struct xkb_key *key;
 
         FAIL_UNLESS(wire->keycode >= keymap->min_key_code &&
                     wire->keycode <= keymap->max_key_code);
 
+        key = &keymap->keys[wire->keycode];
+
         if ((wire->explicit & XCB_XKB_EXPLICIT_KEY_TYPE_1) &&
             key->num_groups > 0)
             key->groups[0].explicit_type = true;
@@ -579,11 +581,12 @@ get_modmaps(struct xkb_keymap *keymap, xcb_connection_t *conn,
 
     for (int i = 0; i < length; i++) {
         xcb_xkb_key_mod_map_t *wire = iter.data;
-        struct xkb_key *key = &keymap->keys[wire->keycode];
+        struct xkb_key *key;
 
         FAIL_UNLESS(wire->keycode >= keymap->min_key_code &&
                     wire->keycode <= keymap->max_key_code);
 
+        key = &keymap->keys[wire->keycode];
         key->modmap = wire->mods;
 
         xcb_xkb_key_mod_map_next(&iter);
@@ -605,11 +608,12 @@ get_vmodmaps(struct xkb_keymap *keymap, xcb_connection_t *conn,
 
     for (int i = 0; i < length; i++) {
         xcb_xkb_key_v_mod_map_t *wire = iter.data;
-        struct xkb_key *key = &keymap->keys[wire->keycode];
+        struct xkb_key *key;
 
         FAIL_UNLESS(wire->keycode >= keymap->min_key_code &&
                     wire->keycode <= keymap->max_key_code);
 
+        key = &keymap->keys[wire->keycode];
         key->vmodmap = translate_mods(0, wire->vmods, 0);
 
         xcb_xkb_key_v_mod_map_next(&iter);