Skip to content

Commit 5812717

Browse files
committed
qemu-keymap: properly check return from xkb_keymap_mod_get_index
We can return XKB_MOD_INVALID for AltGr which rightly gets flagged by sanitisers as an overly wide shift attempt. Properly check the return type and leave the bitmap as zero in that case. Tested output before and after is unchanged with the gb and ara keymaps. Reviewed-by: Juan Quintela <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent af323aa commit 5812717

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

qemu-keymap.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ static void usage(FILE *out)
140140
names.options ?: "-");
141141
}
142142

143+
static xkb_mod_mask_t get_mod(struct xkb_keymap *map, const char *name)
144+
{
145+
xkb_mod_index_t mod;
146+
xkb_mod_mask_t mask = 0;
147+
148+
mod = xkb_keymap_mod_get_index(map, name);
149+
if (mod != XKB_MOD_INVALID) {
150+
mask = (1 << mod);
151+
}
152+
return mask;
153+
}
154+
143155
int main(int argc, char *argv[])
144156
{
145157
struct xkb_context *ctx;
@@ -215,14 +227,10 @@ int main(int argc, char *argv[])
215227
mod, xkb_keymap_mod_get_name(map, mod));
216228
}
217229

218-
mod = xkb_keymap_mod_get_index(map, "Shift");
219-
shift = (1 << mod);
220-
mod = xkb_keymap_mod_get_index(map, "Control");
221-
ctrl = (1 << mod);
222-
mod = xkb_keymap_mod_get_index(map, "AltGr");
223-
altgr = (1 << mod);
224-
mod = xkb_keymap_mod_get_index(map, "NumLock");
225-
numlock = (1 << mod);
230+
shift = get_mod(map, "Shift");
231+
ctrl = get_mod(map, "Control");
232+
altgr = get_mod(map, "AltGr");
233+
numlock = get_mod(map, "NumLock");
226234

227235
state = xkb_state_new(map);
228236
xkb_keymap_key_for_each(map, walk_map, state);

0 commit comments

Comments
 (0)