Fix segfault when connecting keyboard/mouse

Sometimes `device->wlr_device->keyboard->keymap` is NULL.
When that happens, the call to `xkb_keymap_num_layouts` segfaults.
This adds a guard around the handling of `keymap` to prevent that.

This should resolve issues #6502 #6484
This commit is contained in:
Darkhan Kubigenov 2022-05-12 23:19:58 +01:00
parent ffc603d451
commit 6f0b5b9cb3

View file

@ -989,6 +989,7 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
json_object *layouts_arr = json_object_new_array(); json_object *layouts_arr = json_object_new_array();
json_object_object_add(object, "xkb_layout_names", layouts_arr); json_object_object_add(object, "xkb_layout_names", layouts_arr);
if (keymap) {
xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap); xkb_layout_index_t num_layouts = xkb_keymap_num_layouts(keymap);
xkb_layout_index_t layout_idx; xkb_layout_index_t layout_idx;
for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) { for (layout_idx = 0; layout_idx < num_layouts; layout_idx++) {
@ -1006,6 +1007,7 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
} }
} }
} }
}
if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) {
struct input_config *ic = input_device_get_config(device); struct input_config *ic = input_device_get_config(device);