Blame SOURCES/0031-evdev-fix-array-size-calculation-in-decode_bitset_.patch

8e169c
From 96194ed74158f0b9976fae43a910ad14eaea141e Mon Sep 17 00:00:00 2001
8e169c
From: Eugene Syromyatnikov <evgsyr@gmail.com>
8e169c
Date: Fri, 12 Jul 2019 14:57:28 +0200
8e169c
Subject: [PATCH 2/3] evdev: fix array size calculation in decode_bitset_
8e169c
8e169c
max_nr is in bits (as it is a number of flags), result is in bytes, and
8e169c
the array allocation has to be in personality words.
8e169c
8e169c
There's still an open question, however, what to do on big-endian
8e169c
architectures when a non-divisible-by-4 value is returned.
8e169c
8e169c
* evdev.c (decode_bitset_): Declare size_bits, initialise it and use it
8e169c
later instead of size; round up size by personality's word boundary.
8e169c
---
8e169c
 evdev.c | 12 ++++++++----
8e169c
 1 file changed, 8 insertions(+), 4 deletions(-)
8e169c
8e169c
diff --git a/evdev.c b/evdev.c
8e169c
index 4b811cf8..a3d9cb55 100644
8e169c
--- a/evdev.c
8e169c
+++ b/evdev.c
8e169c
@@ -151,10 +151,14 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
8e169c
 	tprints(", ");
8e169c
 
8e169c
 	unsigned int size;
8e169c
+	unsigned int size_bits;
8e169c
+
8e169c
 	if ((kernel_ulong_t) tcp->u_rval > max_nr / 8)
8e169c
-		size = max_nr;
8e169c
+		size_bits = max_nr;
8e169c
 	else
8e169c
-		size = tcp->u_rval * 8;
8e169c
+		size_bits = tcp->u_rval * 8;
8e169c
+
8e169c
+	size = ROUNDUP(ROUNDUP_DIV(size_bits, 8), current_wordsize);
8e169c
 
8e169c
 	if (syserror(tcp) || !size) {
8e169c
 		printaddr(arg);
8e169c
@@ -170,13 +174,13 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,
8e169c
 	tprints("[");
8e169c
 
8e169c
 	int bit_displayed = 0;
8e169c
-	int i = next_set_bit(decoded_arg, 0, size);
8e169c
+	int i = next_set_bit(decoded_arg, 0, size_bits);
8e169c
 	if (i < 0) {
8e169c
 		tprints(" 0 ");
8e169c
 	} else {
8e169c
 		printxval_dispatch(decode_nr, decode_nr_size, i, dflt, xt);
8e169c
 
8e169c
-		while ((i = next_set_bit(decoded_arg, i + 1, size)) > 0) {
8e169c
+		while ((i = next_set_bit(decoded_arg, i + 1, size_bits)) > 0) {
8e169c
 			if (abbrev(tcp) && bit_displayed >= 3) {
8e169c
 				tprints(", ...");
8e169c
 				break;
8e169c
-- 
8e169c
2.13.6
8e169c