[hackers] [sbase][PATCH] shuf: fix possible infinite loop

From: Mattias Andrée <maandree_AT_kth.se>
Date: Wed, 30 Mar 2016 21:40:24 +0200

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
---
 shuf.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/shuf.c b/shuf.c
index a325bb2..51eeecd 100644
--- a/shuf.c
+++ b/shuf.c
_AT_@ -44,8 +44,7 @@ random_byte_libc(void)
 static size_t
 random_int(size_t max)
 {
-	size_t n = max;
-	size_t r = 0;
+	size_t n, r = 0;
 	size_t mask = max;
 	int s = 1;
 
_AT_@ -53,8 +52,7 @@ random_int(size_t max)
 		mask |= mask >> s++;
 
 	do {
-		while (n) {
-			n >>= 8;
+		for (n = max; n; n >>= 8) {
 			r <<= 8;
 			r |= random_byte();
 		}
-- 
2.7.4
Received on Wed Mar 30 2016 - 21:40:24 CEST

This archive was generated by hypermail 2.3.0 : Wed Mar 30 2016 - 21:48:18 CEST