xkbcomp: where a keysym cannot be resolved, set it to NoSymbol Where resolve_keysym fails we warn but use the otherwise uninitialized variable as our keysym. That later ends up in the keymap as random garbage hex value. Simplest test case, set this in the 'us' keymap: key <TLDE> { [ xyz ] }; And without this patch we get random garbage: ./build/xkbcli-compile-keymap --layout us | grep TLDE: key <TLDE> { [ 0x018a5cf0 ] }; With this patch, we now get NoSymbol: ./build/xkbcli-compile-keymap --layout us | grep TLDE: key <TLDE> { [ NoSymbol ] };
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 6dcb523..87dea65 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -726,8 +726,10 @@ KeySyms : OBRACE KeySymList CBRACE
KeySym : IDENT
{
- if (!resolve_keysym($1, &$$))
+ if (!resolve_keysym($1, &$$)) {
parser_warn(param, "unrecognized keysym \"%s\"", $1);
+ $$ = XKB_KEY_NoSymbol;
+ }
free($1);
}
| SECTION { $$ = XKB_KEY_section; }
diff --git a/test/data/symbols/garbage b/test/data/symbols/garbage
new file mode 100644
index 0000000..98c5e28
--- /dev/null
+++ b/test/data/symbols/garbage
@@ -0,0 +1,14 @@
+default alphanumeric_keys
+xkb_symbols "garbage" {
+ include "us"
+
+ name[Group1]= "My garbage Layout";
+
+ // The garbage keysym will *not* override the corresponding symbol from the
+ // 'us' layout
+ key <TLDE> { [ keysym_is_garbage, exclam ] };
+
+ // AE13 is unused by 'us', use it to avoid fallback to the 'us' definition.
+ // Define with 2 levels but first level is a garbage symbol.
+ key <AE13> { [ keysym_is_garbage, asciitilde ] };
+};
diff --git a/test/keymap.c b/test/keymap.c
index a6bade8..816c2e4 100644
--- a/test/keymap.c
+++ b/test/keymap.c
@@ -31,8 +31,51 @@
#include "test.h"
-int
-main(void)
+static void
+test_garbage_key(void)
+{
+ struct xkb_context *context = test_get_context(0);
+ struct xkb_keymap *keymap;
+ xkb_keycode_t kc;
+ int nsyms;
+ const xkb_keysym_t *syms;
+ const xkb_layout_index_t first_layout = 0;
+ xkb_level_index_t nlevels;
+
+ assert(context);
+
+ keymap = test_compile_rules(context, NULL, NULL, "garbage", NULL, NULL);
+ assert(keymap);
+
+ /* TLDE uses the 'us' sym on the first level and is thus [grave, exclam] */
+ kc = xkb_keymap_key_by_name(keymap, "TLDE");
+ assert(kc != XKB_KEYCODE_INVALID);
+ nlevels = xkb_keymap_num_levels_for_key(keymap, kc, first_layout);
+ assert(nlevels == 2);
+ nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &syms);
+ assert(nsyms == 1);
+ assert(*syms == XKB_KEY_grave); /* fallback from 'us' */
+ nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &syms);
+ assert(nsyms == 1);
+ assert(*syms == XKB_KEY_exclam);
+
+ /* AE13 has no 'us' fallback and ends up as [NoSymbol, asciitilde] */
+ kc = xkb_keymap_key_by_name(keymap, "AE13");
+ assert(kc != XKB_KEYCODE_INVALID);
+ nlevels = xkb_keymap_num_levels_for_key(keymap, kc, first_layout);
+ assert(nlevels == 2);
+ nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 0, &syms);
+ assert(nsyms == 0);
+ nsyms = xkb_keymap_key_get_syms_by_level(keymap, kc, first_layout, 1, &syms);
+ assert(nsyms == 1);
+ assert(*syms == XKB_KEY_asciitilde);
+
+ xkb_keymap_unref(keymap);
+ xkb_context_unref(context);
+}
+
+static void
+test_keymap(void)
{
struct xkb_context *context = test_get_context(0);
struct xkb_keymap *keymap;
@@ -105,3 +148,12 @@ main(void)
xkb_keymap_unref(keymap);
xkb_context_unref(context);
}
+
+int
+main(void)
+{
+ test_garbage_key();
+ test_keymap();
+
+ return 0;
+}