Only allow values of 0 and 1 for udev flags. Not that I'm aware of anyone
using anything else (i.e. his shouldn't break anything) but it's best to be as
restrictive as possible here.

Bonus effect: it's now possible to unset LIBINPUT_MODEL_* tags as well,
previously any value (including 0) was counted as "yes".

Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 src/evdev.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index afb5e34..500a0f8 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -93,6 +93,28 @@ static const struct evdev_udev_tag_match 
evdev_udev_tag_matches[] = {
        { 0 },
 };
 
+static inline bool
+parse_udev_flag(struct evdev_device *device,
+               struct udev_device *udev_device,
+               const char *property)
+{
+       const char *val;
+
+       val = udev_device_get_property_value(udev_device, property);
+       if (!val)
+               return false;
+
+       if (streq(val, "1"))
+               return true;
+       if (!streq(val, "0"))
+               log_error(evdev_libinput_context(device),
+                         "%s: property %s has invalid value '%s'\n",
+                         evdev_device_get_sysname(device),
+                         property,
+                         val);
+       return false;
+}
+
 static void
 hw_set_key_down(struct fallback_dispatch *dispatch, int code, int pressed)
 {
@@ -1026,8 +1048,7 @@ evdev_tag_trackpoint(struct evdev_device *device,
 {
        if (libevdev_has_property(device->evdev,
                                  INPUT_PROP_POINTING_STICK) ||
-           udev_device_get_property_value(udev_device,
-                                          "ID_INPUT_POINTINGSTICK"))
+           parse_udev_flag(device, udev_device, "ID_INPUT_POINTINGSTICK"))
                device->tags |= EVDEV_TAG_TRACKPOINT;
 }
 
@@ -2192,12 +2213,11 @@ evdev_read_model_flags(struct evdev_device *device)
        };
        const struct model_map *m = model_map;
        uint32_t model_flags = 0;
-       const char *val;
 
        while (m->property) {
-               val = udev_device_get_property_value(device->udev_device,
-                                                    m->property);
-               if (val && !streq(val, "0")) {
+               if (parse_udev_flag(device,
+                                   device->udev_device,
+                                   m->property)) {
                        log_debug(evdev_libinput_context(device),
                                  "%s: tagged as %s\n",
                                  evdev_device_get_sysname(device),
@@ -2293,7 +2313,6 @@ static enum evdev_device_udev_tags
 evdev_device_get_udev_tags(struct evdev_device *device,
                           struct udev_device *udev_device)
 {
-       const char *prop;
        enum evdev_device_udev_tags tags = 0;
        const struct evdev_udev_tag_match *match;
        int i;
@@ -2301,10 +2320,9 @@ evdev_device_get_udev_tags(struct evdev_device *device,
        for (i = 0; i < 2 && udev_device; i++) {
                match = evdev_udev_tag_matches;
                while (match->name) {
-                       prop = udev_device_get_property_value(
-                                                     udev_device,
-                                                     match->name);
-                       if (prop)
+                       if (parse_udev_flag(device,
+                                           udev_device,
+                                           match->name))
                                tags |= match->tag;
 
                        match++;
-- 
2.9.3

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to