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

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