Blame SOURCES/0033-tests-test-evdev-bitset-decoding-more-thoroughly.patch

35b686
From cdd8206af74fcb961f0179e21eacf5d55d23f0ac Mon Sep 17 00:00:00 2001
35b686
From: Eugene Syromyatnikov <evgsyr@gmail.com>
35b686
Date: Fri, 12 Jul 2019 14:31:44 +0200
35b686
Subject: [PATCH 3/3] tests: test evdev bitset decoding more thoroughly
35b686
35b686
* tests/ioctl_evdev-success-v.test: Inject various values.
35b686
* tests/ioctl_evdev-success.test: Likewise.
35b686
* tests/ioctl_evdev-success.c (NUM_WORDS): New macro.
35b686
(struct evdev_check): Constify arg_ptr and print_arg args.
35b686
(invoke_test_syscall, test_evdev, print_input_absinfo, print_input_id,
35b686
print_mtslots): Add const qualifiers.
35b686
(print_getbit): Add const qualifiers, rewrite to expect trailing NULL
35b686
in the string array instead of leading string count.
35b686
(main): Set size for ev_more, ev_less, ev_zero arrays; replace leading
35b686
count element in ev_more_str, ev_less_str, ev_zero_str with trailing
35b686
NULL; replace ev_more_str and ev_less_str with ev_more_str_2/ev_less_str_2
35b686
and ev_more_str_3/ev_less_str_3 that differ by presence of flags that reside
35b686
beyond first two bytes; add static and const qualifiers where possible;
35b686
add key/key_sts_8/key_str_16 values; update a to provide either ev_more_str_2
35b686
or ev_more_str_3 and either key_str_8 or key_str_16 depending on inject_retval
35b686
value.
35b686
---
35b686
 tests/ioctl_evdev-success-v.test |  15 +++---
35b686
 tests/ioctl_evdev-success.c      | 100 ++++++++++++++++++++++++++-------------
35b686
 tests/ioctl_evdev-success.test   |  15 +++---
35b686
 3 files changed, 84 insertions(+), 46 deletions(-)
35b686
35b686
Index: strace-5.1/tests/ioctl_evdev-success-v.test
35b686
===================================================================
35b686
--- strace-5.1.orig/tests/ioctl_evdev-success-v.test	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests/ioctl_evdev-success-v.test	2019-08-29 12:08:51.568168577 +0200
35b686
@@ -8,11 +8,14 @@
35b686
 . "${srcdir=.}/scno_tampering.sh"
35b686
 
35b686
 : ${IOCTL_INJECT_START=256}
35b686
-: ${IOCTL_INJECT_RETVAL=8}
35b686
 
35b686
 run_prog
35b686
-run_strace -a16 -v -e trace=ioctl \
35b686
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
35b686
-	../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
35b686
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
35b686
-match_diff "$OUT" "$EXP"
35b686
+
35b686
+for ret in 0 2 8 15 16; do
35b686
+	run_strace -a16 -v -e trace=ioctl \
35b686
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
35b686
+		../ioctl_evdev-success-v \
35b686
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
35b686
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
35b686
+	match_diff "$OUT.$ret" "$EXP.$ret"
35b686
+done
35b686
Index: strace-5.1/tests/ioctl_evdev-success.c
35b686
===================================================================
35b686
--- strace-5.1.orig/tests/ioctl_evdev-success.c	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests/ioctl_evdev-success.c	2019-08-29 12:08:51.568168577 +0200
35b686
@@ -9,6 +9,7 @@
35b686
 
35b686
 #ifdef HAVE_LINUX_INPUT_H
35b686
 
35b686
+# include <assert.h>
35b686
 # include <inttypes.h>
35b686
 # include <stdio.h>
35b686
 # include <stdlib.h>
35b686
@@ -16,17 +17,19 @@
35b686
 # include <linux/input.h>
35b686
 # include "print_fields.h"
35b686
 
35b686
+# define NUM_WORDS 4
35b686
+
35b686
 static const char *errstr;
35b686
 
35b686
 struct evdev_check {
35b686
 	unsigned long cmd;
35b686
 	const char *cmd_str;
35b686
-	void *arg_ptr;
35b686
-	void (*print_arg)(long rc, void *ptr, void *arg);
35b686
+	const void *arg_ptr;
35b686
+	void (*print_arg)(long rc, const void *ptr, const void *arg);
35b686
 };
35b686
 
35b686
 static long
35b686
-invoke_test_syscall(unsigned long cmd, void *p)
35b686
+invoke_test_syscall(unsigned long cmd, const void *p)
35b686
 {
35b686
 	long rc = ioctl(-1, cmd, p);
35b686
 	errstr = sprintrc(rc);
35b686
@@ -38,7 +41,7 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-test_evdev(struct evdev_check *check, void *arg)
35b686
+test_evdev(struct evdev_check *check, const void *arg)
35b686
 {
35b686
 	long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
35b686
 	printf("ioctl(-1, %s, ", check->cmd_str);
35b686
@@ -50,9 +53,9 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-print_input_absinfo(long rc, void *ptr, void *arg)
35b686
+print_input_absinfo(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	struct input_absinfo *absinfo = ptr;
35b686
+	const struct input_absinfo *absinfo = ptr;
35b686
 
35b686
 	if (rc < 0) {
35b686
 		printf("%p", absinfo);
35b686
@@ -74,9 +77,9 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-print_input_id(long rc, void *ptr, void *arg)
35b686
+print_input_id(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	struct input_id *id = ptr;
35b686
+	const struct input_id *id = ptr;
35b686
 
35b686
 	if (rc < 0) {
35b686
 		printf("%p", id);
35b686
@@ -91,10 +94,10 @@
35b686
 
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 static void
35b686
-print_mtslots(long rc, void *ptr, void *arg)
35b686
+print_mtslots(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	int *buffer = ptr;
35b686
-	const char **str = arg;
35b686
+	const int *buffer = ptr;
35b686
+	const char * const * str = arg;
35b686
 	int num = atoi(*(str + 1));
35b686
 
35b686
 	if (rc < 0) {
35b686
@@ -111,27 +114,26 @@
35b686
 # endif
35b686
 
35b686
 static void
35b686
-print_getbit(long rc, void *ptr, void *arg)
35b686
+print_getbit(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	const char **str = arg;
35b686
-	int num = atoi(*str);
35b686
+	const char * const *str = arg;
35b686
 
35b686
-	if (rc < 0) {
35b686
+	if (rc <= 0) {
35b686
 		printf("%p", ptr);
35b686
 		return;
35b686
 	}
35b686
 
35b686
 	printf("[");
35b686
-	printf("%s", *(str + 1));
35b686
-	for (unsigned int i = 2; i <= (unsigned) num; i++) {
35b686
+	for (unsigned long i = 0; str[i]; i++) {
35b686
 # if ! VERBOSE
35b686
-		if (i > 4) {
35b686
+		if (i >= 4) {
35b686
 			printf(", ...");
35b686
 			break;
35b686
 		}
35b686
 # endif
35b686
-		printf(", ");
35b686
-		printf("%s", *(str + i));
35b686
+		if (i)
35b686
+			printf(", ");
35b686
+		printf("%s", str[i]);
35b686
 	}
35b686
 	printf("]");
35b686
 }
35b686
@@ -177,6 +179,7 @@
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
35b686
+
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
35b686
 	/* we use the second element to indicate the number of values */
35b686
@@ -190,36 +193,65 @@
35b686
 	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
35b686
 # endif
35b686
 
35b686
+	enum { ULONG_BIT = sizeof(unsigned long) * 8 };
35b686
+
35b686
 	/* set more than 4 bits */
35b686
-	unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
35b686
-	/* we use the first element to indicate the number of set bits */
35b686
-	/* ev_more_str[0] is "5" so the number of set bits is 5 */
35b686
-	const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
35b686
+	static const unsigned long ev_more[NUM_WORDS] = {
35b686
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
35b686
+		| 1 << EV_PWR };
35b686
+	static const char * const ev_more_str_2[] = {
35b686
+		"EV_ABS", "EV_MSC", NULL };
35b686
+	static const char * const ev_more_str_3[] = {
35b686
+		"EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
35b686
 
35b686
 	/* set less than 4 bits */
35b686
-	unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
35b686
-	const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
35b686
+	static const unsigned long ev_less[NUM_WORDS] = {
35b686
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
35b686
+	static const char * const ev_less_str_2[] = {
35b686
+		"EV_ABS", "EV_MSC", NULL };
35b686
+	static const char * const ev_less_str_3[] = {
35b686
+		"EV_ABS", "EV_MSC", "EV_LED", NULL };
35b686
 
35b686
 	/* set zero bit */
35b686
-	unsigned long ev_zero[] = { 0x0 };
35b686
-	const char *ev_zero_str[] = { "0", " 0 " };
35b686
+	static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
35b686
+	static const char * const ev_zero_str[] = { " 0 ", NULL };
35b686
 
35b686
 	/* KEY_MAX is 0x2ff which is greater than retval * 8 */
35b686
-	unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
35b686
-	const char *key_str[] = { "2", "KEY_1", "KEY_2" };
35b686
+	static const unsigned long key[NUM_WORDS] = {
35b686
+		1 << KEY_1 | 1 << KEY_2,
35b686
+		[ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
35b686
+
35b686
+	static const char * const key_str_8[] = {
35b686
+		"KEY_1", "KEY_2", NULL };
35b686
+	static const char * const key_str_16[] = {
35b686
+		"KEY_1", "KEY_2", "KEY_F12", NULL };
35b686
+
35b686
+	assert(sizeof(ev_more) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(ev_less) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(key) >= (unsigned long) inject_retval);
35b686
 
35b686
 	struct {
35b686
 		struct evdev_check check;
35b686
-		void *ptr;
35b686
+		const void *ptr;
35b686
 	} a[] = {
35b686
 		{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
35b686
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
35b686
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
35b686
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
35b686
+			inject_retval * 8 <= EV_LED
35b686
+				? (const void *) &ev_more_str_2
35b686
+				: (const void *) &ev_more_str_3 },
35b686
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
35b686
+			inject_retval * 8 <= EV_LED
35b686
+				? (const void *) &ev_less_str_2
35b686
+				: (const void *) &ev_less_str_3 },
35b686
 		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
35b686
-		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
35b686
+		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
35b686
+			inject_retval * 8 <= KEY_F12
35b686
+				? (const void *) &key_str_8
35b686
+				: (const void *) &key_str_16 },
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 		{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
35b686
 		{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }
35b686
Index: strace-5.1/tests/ioctl_evdev-success.test
35b686
===================================================================
35b686
--- strace-5.1.orig/tests/ioctl_evdev-success.test	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests/ioctl_evdev-success.test	2019-08-29 12:08:51.568168577 +0200
35b686
@@ -8,11 +8,14 @@
35b686
 . "${srcdir=.}/scno_tampering.sh"
35b686
 
35b686
 : ${IOCTL_INJECT_START=256}
35b686
-: ${IOCTL_INJECT_RETVAL=8}
35b686
 
35b686
 run_prog
35b686
-run_strace -a16 -e trace=ioctl \
35b686
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
35b686
-	../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
35b686
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
35b686
-match_diff "$OUT" "$EXP"
35b686
+
35b686
+for ret in 0 2 8 15 16; do
35b686
+	run_strace -a16 -e trace=ioctl \
35b686
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
35b686
+		../ioctl_evdev-success \
35b686
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
35b686
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
35b686
+	match_diff "$OUT.$ret" "$EXP.$ret"
35b686
+done
35b686
Index: strace-5.1/tests-m32/ioctl_evdev-success-v.test
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-m32/ioctl_evdev-success-v.test	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests-m32/ioctl_evdev-success-v.test	2019-08-29 12:08:51.568168577 +0200
35b686
@@ -8,11 +8,14 @@
35b686
 . "${srcdir=.}/scno_tampering.sh"
35b686
 
35b686
 : ${IOCTL_INJECT_START=256}
35b686
-: ${IOCTL_INJECT_RETVAL=8}
35b686
 
35b686
 run_prog
35b686
-run_strace -a16 -v -e trace=ioctl \
35b686
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
35b686
-	../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
35b686
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
35b686
-match_diff "$OUT" "$EXP"
35b686
+
35b686
+for ret in 0 2 8 15 16; do
35b686
+	run_strace -a16 -v -e trace=ioctl \
35b686
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
35b686
+		../ioctl_evdev-success-v \
35b686
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
35b686
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
35b686
+	match_diff "$OUT.$ret" "$EXP.$ret"
35b686
+done
35b686
Index: strace-5.1/tests-m32/ioctl_evdev-success.test
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-m32/ioctl_evdev-success.test	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests-m32/ioctl_evdev-success.test	2019-08-29 12:08:51.568168577 +0200
35b686
@@ -8,11 +8,14 @@
35b686
 . "${srcdir=.}/scno_tampering.sh"
35b686
 
35b686
 : ${IOCTL_INJECT_START=256}
35b686
-: ${IOCTL_INJECT_RETVAL=8}
35b686
 
35b686
 run_prog
35b686
-run_strace -a16 -e trace=ioctl \
35b686
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
35b686
-	../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
35b686
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
35b686
-match_diff "$OUT" "$EXP"
35b686
+
35b686
+for ret in 0 2 8 15 16; do
35b686
+	run_strace -a16 -e trace=ioctl \
35b686
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
35b686
+		../ioctl_evdev-success \
35b686
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
35b686
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
35b686
+	match_diff "$OUT.$ret" "$EXP.$ret"
35b686
+done
35b686
Index: strace-5.1/tests-mx32/ioctl_evdev-success-v.test
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-mx32/ioctl_evdev-success-v.test	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests-mx32/ioctl_evdev-success-v.test	2019-08-29 12:08:51.569168564 +0200
35b686
@@ -8,11 +8,14 @@
35b686
 . "${srcdir=.}/scno_tampering.sh"
35b686
 
35b686
 : ${IOCTL_INJECT_START=256}
35b686
-: ${IOCTL_INJECT_RETVAL=8}
35b686
 
35b686
 run_prog
35b686
-run_strace -a16 -v -e trace=ioctl \
35b686
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
35b686
-	../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
35b686
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
35b686
-match_diff "$OUT" "$EXP"
35b686
+
35b686
+for ret in 0 2 8 15 16; do
35b686
+	run_strace -a16 -v -e trace=ioctl \
35b686
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
35b686
+		../ioctl_evdev-success-v \
35b686
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
35b686
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
35b686
+	match_diff "$OUT.$ret" "$EXP.$ret"
35b686
+done
35b686
Index: strace-5.1/tests-mx32/ioctl_evdev-success.test
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-mx32/ioctl_evdev-success.test	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests-mx32/ioctl_evdev-success.test	2019-08-29 12:08:51.569168564 +0200
35b686
@@ -8,11 +8,14 @@
35b686
 . "${srcdir=.}/scno_tampering.sh"
35b686
 
35b686
 : ${IOCTL_INJECT_START=256}
35b686
-: ${IOCTL_INJECT_RETVAL=8}
35b686
 
35b686
 run_prog
35b686
-run_strace -a16 -e trace=ioctl \
35b686
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
35b686
-	../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
35b686
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
35b686
-match_diff "$OUT" "$EXP"
35b686
+
35b686
+for ret in 0 2 8 15 16; do
35b686
+	run_strace -a16 -e trace=ioctl \
35b686
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
35b686
+		../ioctl_evdev-success \
35b686
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
35b686
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
35b686
+	match_diff "$OUT.$ret" "$EXP.$ret"
35b686
+done
35b686
Index: strace-5.1/tests-m32/ioctl_evdev-success.c
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-m32/ioctl_evdev-success.c	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests-m32/ioctl_evdev-success.c	2019-08-29 12:09:27.898700830 +0200
35b686
@@ -9,6 +9,7 @@
35b686
 
35b686
 #ifdef HAVE_LINUX_INPUT_H
35b686
 
35b686
+# include <assert.h>
35b686
 # include <inttypes.h>
35b686
 # include <stdio.h>
35b686
 # include <stdlib.h>
35b686
@@ -16,17 +17,19 @@
35b686
 # include <linux/input.h>
35b686
 # include "print_fields.h"
35b686
 
35b686
+# define NUM_WORDS 4
35b686
+
35b686
 static const char *errstr;
35b686
 
35b686
 struct evdev_check {
35b686
 	unsigned long cmd;
35b686
 	const char *cmd_str;
35b686
-	void *arg_ptr;
35b686
-	void (*print_arg)(long rc, void *ptr, void *arg);
35b686
+	const void *arg_ptr;
35b686
+	void (*print_arg)(long rc, const void *ptr, const void *arg);
35b686
 };
35b686
 
35b686
 static long
35b686
-invoke_test_syscall(unsigned long cmd, void *p)
35b686
+invoke_test_syscall(unsigned long cmd, const void *p)
35b686
 {
35b686
 	long rc = ioctl(-1, cmd, p);
35b686
 	errstr = sprintrc(rc);
35b686
@@ -38,7 +41,7 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-test_evdev(struct evdev_check *check, void *arg)
35b686
+test_evdev(struct evdev_check *check, const void *arg)
35b686
 {
35b686
 	long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
35b686
 	printf("ioctl(-1, %s, ", check->cmd_str);
35b686
@@ -50,9 +53,9 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-print_input_absinfo(long rc, void *ptr, void *arg)
35b686
+print_input_absinfo(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	struct input_absinfo *absinfo = ptr;
35b686
+	const struct input_absinfo *absinfo = ptr;
35b686
 
35b686
 	if (rc < 0) {
35b686
 		printf("%p", absinfo);
35b686
@@ -74,9 +77,9 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-print_input_id(long rc, void *ptr, void *arg)
35b686
+print_input_id(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	struct input_id *id = ptr;
35b686
+	const struct input_id *id = ptr;
35b686
 
35b686
 	if (rc < 0) {
35b686
 		printf("%p", id);
35b686
@@ -91,10 +94,10 @@
35b686
 
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 static void
35b686
-print_mtslots(long rc, void *ptr, void *arg)
35b686
+print_mtslots(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	int *buffer = ptr;
35b686
-	const char **str = arg;
35b686
+	const int *buffer = ptr;
35b686
+	const char * const * str = arg;
35b686
 	int num = atoi(*(str + 1));
35b686
 
35b686
 	if (rc < 0) {
35b686
@@ -111,27 +114,26 @@
35b686
 # endif
35b686
 
35b686
 static void
35b686
-print_getbit(long rc, void *ptr, void *arg)
35b686
+print_getbit(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	const char **str = arg;
35b686
-	int num = atoi(*str);
35b686
+	const char * const *str = arg;
35b686
 
35b686
-	if (rc < 0) {
35b686
+	if (rc <= 0) {
35b686
 		printf("%p", ptr);
35b686
 		return;
35b686
 	}
35b686
 
35b686
 	printf("[");
35b686
-	printf("%s", *(str + 1));
35b686
-	for (unsigned int i = 2; i <= (unsigned) num; i++) {
35b686
+	for (unsigned long i = 0; str[i]; i++) {
35b686
 # if ! VERBOSE
35b686
-		if (i > 4) {
35b686
+		if (i >= 4) {
35b686
 			printf(", ...");
35b686
 			break;
35b686
 		}
35b686
 # endif
35b686
-		printf(", ");
35b686
-		printf("%s", *(str + i));
35b686
+		if (i)
35b686
+			printf(", ");
35b686
+		printf("%s", str[i]);
35b686
 	}
35b686
 	printf("]");
35b686
 }
35b686
@@ -177,6 +179,7 @@
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
35b686
+
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
35b686
 	/* we use the second element to indicate the number of values */
35b686
@@ -190,36 +193,65 @@
35b686
 	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
35b686
 # endif
35b686
 
35b686
+	enum { ULONG_BIT = sizeof(unsigned long) * 8 };
35b686
+
35b686
 	/* set more than 4 bits */
35b686
-	unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
35b686
-	/* we use the first element to indicate the number of set bits */
35b686
-	/* ev_more_str[0] is "5" so the number of set bits is 5 */
35b686
-	const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
35b686
+	static const unsigned long ev_more[NUM_WORDS] = {
35b686
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
35b686
+		| 1 << EV_PWR };
35b686
+	static const char * const ev_more_str_2[] = {
35b686
+		"EV_ABS", "EV_MSC", NULL };
35b686
+	static const char * const ev_more_str_3[] = {
35b686
+		"EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
35b686
 
35b686
 	/* set less than 4 bits */
35b686
-	unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
35b686
-	const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
35b686
+	static const unsigned long ev_less[NUM_WORDS] = {
35b686
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
35b686
+	static const char * const ev_less_str_2[] = {
35b686
+		"EV_ABS", "EV_MSC", NULL };
35b686
+	static const char * const ev_less_str_3[] = {
35b686
+		"EV_ABS", "EV_MSC", "EV_LED", NULL };
35b686
 
35b686
 	/* set zero bit */
35b686
-	unsigned long ev_zero[] = { 0x0 };
35b686
-	const char *ev_zero_str[] = { "0", " 0 " };
35b686
+	static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
35b686
+	static const char * const ev_zero_str[] = { " 0 ", NULL };
35b686
 
35b686
 	/* KEY_MAX is 0x2ff which is greater than retval * 8 */
35b686
-	unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
35b686
-	const char *key_str[] = { "2", "KEY_1", "KEY_2" };
35b686
+	static const unsigned long key[NUM_WORDS] = {
35b686
+		1 << KEY_1 | 1 << KEY_2,
35b686
+		[ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
35b686
+
35b686
+	static const char * const key_str_8[] = {
35b686
+		"KEY_1", "KEY_2", NULL };
35b686
+	static const char * const key_str_16[] = {
35b686
+		"KEY_1", "KEY_2", "KEY_F12", NULL };
35b686
+
35b686
+	assert(sizeof(ev_more) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(ev_less) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(key) >= (unsigned long) inject_retval);
35b686
 
35b686
 	struct {
35b686
 		struct evdev_check check;
35b686
-		void *ptr;
35b686
+		const void *ptr;
35b686
 	} a[] = {
35b686
 		{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
35b686
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
35b686
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
35b686
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
35b686
+			inject_retval * 8 <= EV_LED
35b686
+				? (const void *) &ev_more_str_2
35b686
+				: (const void *) &ev_more_str_3 },
35b686
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
35b686
+			inject_retval * 8 <= EV_LED
35b686
+				? (const void *) &ev_less_str_2
35b686
+				: (const void *) &ev_less_str_3 },
35b686
 		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
35b686
-		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
35b686
+		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
35b686
+			inject_retval * 8 <= KEY_F12
35b686
+				? (const void *) &key_str_8
35b686
+				: (const void *) &key_str_16 },
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 		{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
35b686
 		{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }
35b686
Index: strace-5.1/tests-mx32/ioctl_evdev-success.c
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-mx32/ioctl_evdev-success.c	2018-12-25 00:46:43.000000000 +0100
35b686
+++ strace-5.1/tests-mx32/ioctl_evdev-success.c	2019-08-29 12:09:30.350669261 +0200
35b686
@@ -9,6 +9,7 @@
35b686
 
35b686
 #ifdef HAVE_LINUX_INPUT_H
35b686
 
35b686
+# include <assert.h>
35b686
 # include <inttypes.h>
35b686
 # include <stdio.h>
35b686
 # include <stdlib.h>
35b686
@@ -16,17 +17,19 @@
35b686
 # include <linux/input.h>
35b686
 # include "print_fields.h"
35b686
 
35b686
+# define NUM_WORDS 4
35b686
+
35b686
 static const char *errstr;
35b686
 
35b686
 struct evdev_check {
35b686
 	unsigned long cmd;
35b686
 	const char *cmd_str;
35b686
-	void *arg_ptr;
35b686
-	void (*print_arg)(long rc, void *ptr, void *arg);
35b686
+	const void *arg_ptr;
35b686
+	void (*print_arg)(long rc, const void *ptr, const void *arg);
35b686
 };
35b686
 
35b686
 static long
35b686
-invoke_test_syscall(unsigned long cmd, void *p)
35b686
+invoke_test_syscall(unsigned long cmd, const void *p)
35b686
 {
35b686
 	long rc = ioctl(-1, cmd, p);
35b686
 	errstr = sprintrc(rc);
35b686
@@ -38,7 +41,7 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-test_evdev(struct evdev_check *check, void *arg)
35b686
+test_evdev(struct evdev_check *check, const void *arg)
35b686
 {
35b686
 	long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
35b686
 	printf("ioctl(-1, %s, ", check->cmd_str);
35b686
@@ -50,9 +53,9 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-print_input_absinfo(long rc, void *ptr, void *arg)
35b686
+print_input_absinfo(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	struct input_absinfo *absinfo = ptr;
35b686
+	const struct input_absinfo *absinfo = ptr;
35b686
 
35b686
 	if (rc < 0) {
35b686
 		printf("%p", absinfo);
35b686
@@ -74,9 +77,9 @@
35b686
 }
35b686
 
35b686
 static void
35b686
-print_input_id(long rc, void *ptr, void *arg)
35b686
+print_input_id(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	struct input_id *id = ptr;
35b686
+	const struct input_id *id = ptr;
35b686
 
35b686
 	if (rc < 0) {
35b686
 		printf("%p", id);
35b686
@@ -91,10 +94,10 @@
35b686
 
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 static void
35b686
-print_mtslots(long rc, void *ptr, void *arg)
35b686
+print_mtslots(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	int *buffer = ptr;
35b686
-	const char **str = arg;
35b686
+	const int *buffer = ptr;
35b686
+	const char * const * str = arg;
35b686
 	int num = atoi(*(str + 1));
35b686
 
35b686
 	if (rc < 0) {
35b686
@@ -111,27 +114,26 @@
35b686
 # endif
35b686
 
35b686
 static void
35b686
-print_getbit(long rc, void *ptr, void *arg)
35b686
+print_getbit(long rc, const void *ptr, const void *arg)
35b686
 {
35b686
-	const char **str = arg;
35b686
-	int num = atoi(*str);
35b686
+	const char * const *str = arg;
35b686
 
35b686
-	if (rc < 0) {
35b686
+	if (rc <= 0) {
35b686
 		printf("%p", ptr);
35b686
 		return;
35b686
 	}
35b686
 
35b686
 	printf("[");
35b686
-	printf("%s", *(str + 1));
35b686
-	for (unsigned int i = 2; i <= (unsigned) num; i++) {
35b686
+	for (unsigned long i = 0; str[i]; i++) {
35b686
 # if ! VERBOSE
35b686
-		if (i > 4) {
35b686
+		if (i >= 4) {
35b686
 			printf(", ...");
35b686
 			break;
35b686
 		}
35b686
 # endif
35b686
-		printf(", ");
35b686
-		printf("%s", *(str + i));
35b686
+		if (i)
35b686
+			printf(", ");
35b686
+		printf("%s", str[i]);
35b686
 	}
35b686
 	printf("]");
35b686
 }
35b686
@@ -177,6 +179,7 @@
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
35b686
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
35b686
+
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
35b686
 	/* we use the second element to indicate the number of values */
35b686
@@ -190,36 +193,65 @@
35b686
 	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
35b686
 # endif
35b686
 
35b686
+	enum { ULONG_BIT = sizeof(unsigned long) * 8 };
35b686
+
35b686
 	/* set more than 4 bits */
35b686
-	unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
35b686
-	/* we use the first element to indicate the number of set bits */
35b686
-	/* ev_more_str[0] is "5" so the number of set bits is 5 */
35b686
-	const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
35b686
+	static const unsigned long ev_more[NUM_WORDS] = {
35b686
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
35b686
+		| 1 << EV_PWR };
35b686
+	static const char * const ev_more_str_2[] = {
35b686
+		"EV_ABS", "EV_MSC", NULL };
35b686
+	static const char * const ev_more_str_3[] = {
35b686
+		"EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
35b686
 
35b686
 	/* set less than 4 bits */
35b686
-	unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
35b686
-	const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
35b686
+	static const unsigned long ev_less[NUM_WORDS] = {
35b686
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
35b686
+	static const char * const ev_less_str_2[] = {
35b686
+		"EV_ABS", "EV_MSC", NULL };
35b686
+	static const char * const ev_less_str_3[] = {
35b686
+		"EV_ABS", "EV_MSC", "EV_LED", NULL };
35b686
 
35b686
 	/* set zero bit */
35b686
-	unsigned long ev_zero[] = { 0x0 };
35b686
-	const char *ev_zero_str[] = { "0", " 0 " };
35b686
+	static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
35b686
+	static const char * const ev_zero_str[] = { " 0 ", NULL };
35b686
 
35b686
 	/* KEY_MAX is 0x2ff which is greater than retval * 8 */
35b686
-	unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
35b686
-	const char *key_str[] = { "2", "KEY_1", "KEY_2" };
35b686
+	static const unsigned long key[NUM_WORDS] = {
35b686
+		1 << KEY_1 | 1 << KEY_2,
35b686
+		[ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
35b686
+
35b686
+	static const char * const key_str_8[] = {
35b686
+		"KEY_1", "KEY_2", NULL };
35b686
+	static const char * const key_str_16[] = {
35b686
+		"KEY_1", "KEY_2", "KEY_F12", NULL };
35b686
+
35b686
+	assert(sizeof(ev_more) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(ev_less) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
35b686
+	assert(sizeof(key) >= (unsigned long) inject_retval);
35b686
 
35b686
 	struct {
35b686
 		struct evdev_check check;
35b686
-		void *ptr;
35b686
+		const void *ptr;
35b686
 	} a[] = {
35b686
 		{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
35b686
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
35b686
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
35b686
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
35b686
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
35b686
+			inject_retval * 8 <= EV_LED
35b686
+				? (const void *) &ev_more_str_2
35b686
+				: (const void *) &ev_more_str_3 },
35b686
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
35b686
+			inject_retval * 8 <= EV_LED
35b686
+				? (const void *) &ev_less_str_2
35b686
+				: (const void *) &ev_less_str_3 },
35b686
 		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
35b686
-		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
35b686
+		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
35b686
+			inject_retval * 8 <= KEY_F12
35b686
+				? (const void *) &key_str_8
35b686
+				: (const void *) &key_str_16 },
35b686
 # ifdef EVIOCGMTSLOTS
35b686
 		{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
35b686
 		{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }