Blame 0010-iscsi-tools-fix-get_random_bytes-error-handling.patch

0e55d5
From a7afdf46c3193eb102cc6ec2a3b61e8d36794437 Mon Sep 17 00:00:00 2001
0e55d5
From: Mike Christie <michaelc@cs.wisc.edu>
0e55d5
Date: Fri, 14 Dec 2012 12:40:27 -0600
0e55d5
Subject: iscsi tools: fix get_random_bytes error handling
0e55d5
0e55d5
Bug report from Rahul:
0e55d5
0e55d5
There seems to be a bug in function get_random_bytes(). I reported
0e55d5
this earlier as well but somehow it didn't appear here.
0e55d5
0e55d5
get_random_bytes(unsigned char *data, unsigned int length)
0e55d5
{
0e55d5
	long r;
0e55d5
        unsigned n;
0e55d5
	int fd;
0e55d5
0e55d5
	fd = open("/dev/urandom", O_RDONLY);
0e55d5
        	while (length > 0) {
0e55d5
0e55d5
	if (!fd || read(fd, &r, sizeof(long)) != -1)      <<<< the condition is
0e55d5
incorrect
0e55d5
---
0e55d5
 usr/auth.c | 8 ++++----
0e55d5
 1 file changed, 4 insertions(+), 4 deletions(-)
0e55d5
0e55d5
diff --git a/usr/auth.c b/usr/auth.c
0e55d5
index c924545..4ff0425 100644
0e55d5
--- a/usr/auth.c
0e55d5
+++ b/usr/auth.c
0e55d5
@@ -189,24 +189,24 @@ get_random_bytes(unsigned char *data, unsigned int length)
0e55d5
 
0e55d5
 	long r;
0e55d5
         unsigned n;
0e55d5
-	int fd;
0e55d5
+	int fd, r_size = sizeof(r);
0e55d5
 
0e55d5
 	fd = open("/dev/urandom", O_RDONLY);
0e55d5
         while (length > 0) {
0e55d5
 
0e55d5
-		if (!fd || read(fd, &r, sizeof(long)) != -1)
0e55d5
+		if (fd == -1 || read(fd, &r, r_size) != r_size)
0e55d5
 			r = rand();
0e55d5
                 r = r ^ (r >> 8);
0e55d5
                 r = r ^ (r >> 4);
0e55d5
                 n = r & 0x7;
0e55d5
 
0e55d5
-		if (!fd || read(fd, &r, sizeof(long)) != -1)
0e55d5
+		if (fd == -1 || read(fd, &r, r_size) != r_size)
0e55d5
 			r = rand();
0e55d5
                 r = r ^ (r >> 8);
0e55d5
                 r = r ^ (r >> 5);
0e55d5
                 n = (n << 3) | (r & 0x7);
0e55d5
 
0e55d5
-		if (!fd || read(fd, &r, sizeof(long)) != -1)
0e55d5
+		if (fd == -1 || read(fd, &r, r_size) != r_size)
0e55d5
 			r = rand();
0e55d5
                 r = r ^ (r >> 8);
0e55d5
                 r = r ^ (r >> 5);
0e55d5
-- 
0e55d5
1.7.11.7
0e55d5