diff options
author | Mike Christie <michaelc@cs.wisc.edu> | 2012-12-14 12:40:27 -0600 |
---|---|---|
committer | Mike Christie <michaelc@cs.wisc.edu> | 2012-12-14 12:40:27 -0600 |
commit | a7afdf46c3193eb102cc6ec2a3b61e8d36794437 (patch) | |
tree | f486700738dc5e7ac002656fe473c2b9d53c0f91 /usr | |
parent | c34e0bdcbafdb6f9304e1474d51fe1c789c5dea2 (diff) | |
download | open-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')
-rw-r--r-- | usr/auth.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -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); |