aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-12-18 09:17:39 -0500
committerGitHub <noreply@github.com>2017-12-18 09:17:39 -0500
commitc91523c57888c257fa650ffa2574c470f7a788fe (patch)
treefe7204f84390b3189064cb5bf8672eade603a57f
parent3d07d260cb45b79d3612a36766c870fdd1606f0b (diff)
parent2c31cac11623207a02c33734bc77d4ee3b286e8a (diff)
Merge pull request #499 from emersion/unknown-keymap
Do not segfault when loading an unknown keymap
-rw-r--r--rootston/keyboard.c12
-rw-r--r--types/wlr_keyboard.c8
2 files changed, 15 insertions, 5 deletions
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index 4aaf2d48..758a49fb 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -354,8 +354,16 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
wlr_log(L_ERROR, "Cannot create XKB context");
return NULL;
}
- wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context,
- &rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
+
+ struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules,
+ XKB_KEYMAP_COMPILE_NO_FLAGS);
+ if (keymap == NULL) {
+ xkb_context_unref(context);
+ wlr_log(L_ERROR, "Cannot create XKB keymap");
+ return NULL;
+ }
+
+ wlr_keyboard_set_keymap(device->keyboard, keymap);
xkb_context_unref(context);
int repeat_rate = (config->repeat_rate > 0) ? config->repeat_rate : 25;
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c
index c494b45d..ef577e01 100644
--- a/types/wlr_keyboard.c
+++ b/types/wlr_keyboard.c
@@ -1,4 +1,3 @@
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
@@ -132,9 +131,12 @@ void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) {
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
struct xkb_keymap *keymap) {
- wlr_log(L_DEBUG, "Keymap set");
+ kb->xkb_state = xkb_state_new(kb->keymap);
+ if (kb->xkb_state == NULL) {
+ wlr_log(L_ERROR, "Failed to create XKB state");
+ return;
+ }
kb->keymap = keymap;
- assert(kb->xkb_state = xkb_state_new(kb->keymap));
const char *led_names[WLR_LED_COUNT] = {
XKB_LED_NAME_NUM,