summaryrefslogtreecommitdiff
path: root/libevdev/libevdev.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-10-24 14:30:40 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2013-10-24 15:13:41 +1000
commitc4111f717a404ef5a726aa2dd420daa654455af5 (patch)
treebb42a26bdd0e0930242d93c6747c12ad931745f4 /libevdev/libevdev.c
parent521ba2300e548c0ce7634108d5edaef834a023ed (diff)
downloadlibevdev-c4111f717a404ef5a726aa2dd420daa654455af5.tar.gz
Check max to see if an event type is valid
There's a gap in the range between EV_SW and EV_LED. Trying to enable one of those bits will segfault. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'libevdev/libevdev.c')
-rw-r--r--libevdev/libevdev.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 7bebe32..ca57e26 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -1139,12 +1139,18 @@ libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct inpu
LIBEVDEV_EXPORT int
libevdev_enable_event_type(struct libevdev *dev, unsigned int type)
{
+ int max;
+
if (type > EV_MAX)
return -1;
if (libevdev_has_event_type(dev, type))
return 0;
+ max = libevdev_event_type_get_max(type);
+ if (max == -1)
+ return -1;
+
set_bit(dev->bits, type);
if (type == EV_REP) {
@@ -1158,9 +1164,15 @@ libevdev_enable_event_type(struct libevdev *dev, unsigned int type)
LIBEVDEV_EXPORT int
libevdev_disable_event_type(struct libevdev *dev, unsigned int type)
{
+ int max;
+
if (type > EV_MAX || type == EV_SYN)
return -1;
+ max = libevdev_event_type_get_max(type);
+ if (max == -1)
+ return -1;
+
clear_bit(dev->bits, type);
return 0;
@@ -1192,7 +1204,7 @@ libevdev_enable_event_code(struct libevdev *dev, unsigned int type,
max = type_to_mask(dev, type, &mask);
- if (code > max)
+ if (code > max || (int)max == -1)
return -1;
set_bit(mask, code);
@@ -1219,7 +1231,7 @@ libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned in
max = type_to_mask(dev, type, &mask);
- if (code > max)
+ if (code > max || (int)max == -1)
return -1;
clear_bit(mask, code);