summaryrefslogtreecommitdiff
path: root/usr/auth.c
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2012-12-14 12:40:27 -0600
committerMike Christie <michaelc@cs.wisc.edu>2012-12-14 12:40:27 -0600
commita7afdf46c3193eb102cc6ec2a3b61e8d36794437 (patch)
treef486700738dc5e7ac002656fe473c2b9d53c0f91 /usr/auth.c
parentc34e0bdcbafdb6f9304e1474d51fe1c789c5dea2 (diff)
downloadopen-iscsi-a7afdf46c3193eb102cc6ec2a3b61e8d36794437.tar.gz
iscsi tools: fix get_random_bytes error handling
Bug report from Rahul: There seems to be a bug in function get_random_bytes(). I reported this earlier as well but somehow it didn't appear here. get_random_bytes(unsigned char *data, unsigned int length) { long r; unsigned n; int fd; fd = open("/dev/urandom", O_RDONLY); while (length > 0) { if (!fd || read(fd, &r, sizeof(long)) != -1) <<<< the condition is incorrect
Diffstat (limited to 'usr/auth.c')
-rw-r--r--usr/auth.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/usr/auth.c b/usr/auth.c
index c924545..4ff0425 100644
--- a/usr/auth.c
+++ b/usr/auth.c
@@ -189,24 +189,24 @@ get_random_bytes(unsigned char *data, unsigned int length)
long r;
unsigned n;
- int fd;
+ int fd, r_size = sizeof(r);
fd = open("/dev/urandom", O_RDONLY);
while (length > 0) {
- if (!fd || read(fd, &r, sizeof(long)) != -1)
+ if (fd == -1 || read(fd, &r, r_size) != r_size)
r = rand();
r = r ^ (r >> 8);
r = r ^ (r >> 4);
n = r & 0x7;
- if (!fd || read(fd, &r, sizeof(long)) != -1)
+ if (fd == -1 || read(fd, &r, r_size) != r_size)
r = rand();
r = r ^ (r >> 8);
r = r ^ (r >> 5);
n = (n << 3) | (r & 0x7);
- if (!fd || read(fd, &r, sizeof(long)) != -1)
+ if (fd == -1 || read(fd, &r, r_size) != r_size)
r = rand();
r = r ^ (r >> 8);
r = r ^ (r >> 5);