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

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