tablet: avoid errors calling libevdev_get_abs_info()
authorJosé Expósito <jose.exposito89@gmail.com>
Mon, 3 Oct 2022 10:53:22 +0000 (12:53 +0200)
committerJosé Expósito <jose.exposito89@gmail.com>
Mon, 3 Oct 2022 10:53:22 +0000 (12:53 +0200)
Commit 806d4a1393db ("tablet: check libevdev_get_abs_info() return
value") prevented a crash when tilt was deactivated by a quirk.
For more information check [1].

Add similar checks before calling libevdev_get_abs_info() to avoid
possible crashes.

[1] https://gitlab.freedesktop.org/libinput/libinput/-/issues/805
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
src/evdev-tablet.c

index 6094bd5..68c3c3e 100644 (file)
@@ -455,6 +455,10 @@ tablet_update_xy(struct tablet_dispatch *tablet,
        const struct input_absinfo *absinfo;
        int value;
 
+       if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X) ||
+           !libevdev_has_event_code(device->evdev, EV_ABS, ABS_Y))
+               return;
+
        if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
            bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) {
                absinfo = libevdev_get_abs_info(device->evdev, ABS_X);
@@ -528,6 +532,9 @@ tablet_update_pressure(struct tablet_dispatch *tablet,
 {
        const struct input_absinfo *absinfo;
 
+       if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_PRESSURE))
+               return;
+
        if (bit_is_set(tablet->changed_axes,
                       LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
                absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
@@ -541,6 +548,9 @@ tablet_update_distance(struct tablet_dispatch *tablet,
 {
        const struct input_absinfo *absinfo;
 
+       if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_DISTANCE))
+               return;
+
        if (bit_is_set(tablet->changed_axes,
                       LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) {
                absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
@@ -554,6 +564,9 @@ tablet_update_slider(struct tablet_dispatch *tablet,
 {
        const struct input_absinfo *absinfo;
 
+       if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_WHEEL))
+               return;
+
        if (bit_is_set(tablet->changed_axes,
                       LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) {
                absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL);
@@ -597,6 +610,9 @@ tablet_update_artpen_rotation(struct tablet_dispatch *tablet,
 {
        const struct input_absinfo *absinfo;
 
+       if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_Z))
+               return;
+
        if (bit_is_set(tablet->changed_axes,
                       LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) {
                absinfo = libevdev_get_abs_info(device->evdev,