From 417cc5c39449d0780c829a7da7993fedd67039e1 Mon Sep 17 00:00:00 2001 From: Raheman Vaiya Date: Fri, 25 Mar 2022 20:28:52 -0400 Subject: [PATCH] Add more checks to vkbd creation --- src/vkbd/uinput.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/vkbd/uinput.c b/src/vkbd/uinput.c index 6d311f5..fd061da 100644 --- a/src/vkbd/uinput.c +++ b/src/vkbd/uinput.c @@ -80,13 +80,28 @@ static int create_virtual_keyboard(const char *name) exit(-1); } - ioctl(fd, UI_SET_EVBIT, EV_KEY); - ioctl(fd, UI_SET_EVBIT, EV_REL); - ioctl(fd, UI_SET_EVBIT, EV_SYN); + if (ioctl(fd, UI_SET_EVBIT, EV_KEY)) { + perror("ioctl set_evbit"); + exit(-1); + } + + if (ioctl(fd, UI_SET_EVBIT, EV_REL)) { + perror("ioctl set_evbit"); + exit(-1); + } + + if (ioctl(fd, UI_SET_EVBIT, EV_SYN)) { + perror("ioctl set_evbit"); + exit(-1); + } for (code = 0; code < 256; code++) { - if (keycode_table[code].name) - ioctl(fd, UI_SET_KEYBIT, code); + if (keycode_table[code].name) { + if (ioctl(fd, UI_SET_KEYBIT, code)) { + perror("ioctl set_keybit"); + exit(-1); + } + } } memset(&usetup, 0, sizeof(usetup)); @@ -95,8 +110,15 @@ static int create_virtual_keyboard(const char *name) usetup.id.product = 0x0ADE; strcpy(usetup.name, name); - ioctl(fd, UI_DEV_SETUP, &usetup); - ioctl(fd, UI_DEV_CREATE); + if (ioctl(fd, UI_DEV_SETUP, &usetup)) { + perror("ioctl dev_setup"); + exit(-1); + } + + if (ioctl(fd, UI_DEV_CREATE)) { + perror("ioctl dev_create"); + exit(-1); + } return fd; }