[PATCH v1] fix decoder of ioctl EVIOCGBIT

Zhibin Li 08826794brmt at gmail.com
Thu Aug 2 16:23:03 UTC 2018


EV_SYN in EVIOCGBIT should be decoded to get other event types EV_*, not
the precise event codes SYN_*.

* evdev.c: Include "xlat/evdev_ev.h" and remove "xlat/evdev_sync.h".
(decode_bitset_): Fix the incorrect comparison between tcp->u_rval and
max_nr.
(bit_ioctl) <case EV_SYN>: Use evdev_ev and XT_NORMAL in decode_bitset
invocation instead.
* ioctl.c: Print 0 instead of EV_SYN if nr equals to 0x20.
---
 evdev.c | 10 +++++-----
 ioctl.c |  6 +++++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/evdev.c b/evdev.c
index 247ee0e0..037c7869 100644
--- a/evdev.c
+++ b/evdev.c
@@ -38,6 +38,7 @@
 # include <linux/input.h>
 
 # include "xlat/evdev_autorepeat.h"
+# include "xlat/evdev_ev.h"
 # include "xlat/evdev_ff_status.h"
 # include "xlat/evdev_ff_types.h"
 # include "xlat/evdev_keycode.h"
@@ -48,7 +49,6 @@
 # include "xlat/evdev_relative_axes.h"
 # include "xlat/evdev_snd.h"
 # include "xlat/evdev_switch.h"
-# include "xlat/evdev_sync.h"
 
 # ifndef SYN_MAX
 #  define SYN_MAX 0xf
@@ -166,10 +166,10 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
 	tprints(", ");
 
 	unsigned int size;
-	if ((kernel_ulong_t) tcp->u_rval > max_nr)
+	if ((kernel_ulong_t) tcp->u_rval * 8 > max_nr)
 		size = max_nr;
 	else
-		size = tcp->u_rval;
+		size = tcp->u_rval * 8;
 	char decoded_arg[size];
 
 	if (umove_or_printaddr(tcp, arg, &decoded_arg))
@@ -254,8 +254,8 @@ bit_ioctl(struct tcb *const tcp, const unsigned int ev_nr,
 {
 	switch (ev_nr) {
 		case EV_SYN:
-			return decode_bitset(tcp, arg, evdev_sync,
-					     SYN_MAX, "SYN_???", XT_INDEXED);
+			return decode_bitset(tcp, arg, evdev_ev,
+					     EV_MAX, "EV_???", XT_NORMAL);
 		case EV_KEY:
 			return decode_bitset(tcp, arg, evdev_keycode,
 					     KEY_MAX, "KEY_???", XT_INDEXED);
diff --git a/ioctl.c b/ioctl.c
index 93fb5263..d56bf69e 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -99,7 +99,11 @@ evdev_decode_number(const unsigned int code)
 
 	if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
 		tprints("EVIOCGBIT(");
-		printxval(evdev_ev, nr - 0x20, "EV_???");
+		/* There is no EV_SYN in EVIOCGBIT */
+		if (nr == 0x20)
+			tprintf("0");
+		else
+			printxval(evdev_ev, nr - 0x20, "EV_???");
 		tprintf(", %u)", _IOC_SIZE(code));
 		return 1;
 	} else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {
-- 
2.17.1



More information about the Strace-devel mailing list