]>
Commit | Line | Data |
---|---|---|
092b90ae SS |
1 | From a7afdf46c3193eb102cc6ec2a3b61e8d36794437 Mon Sep 17 00:00:00 2001 |
2 | From: Mike Christie <michaelc@cs.wisc.edu> | |
3 | Date: Fri, 14 Dec 2012 12:40:27 -0600 | |
4 | Subject: iscsi tools: fix get_random_bytes error handling | |
5 | ||
6 | Bug report from Rahul: | |
7 | ||
8 | There seems to be a bug in function get_random_bytes(). I reported | |
9 | this earlier as well but somehow it didn't appear here. | |
10 | ||
11 | get_random_bytes(unsigned char *data, unsigned int length) | |
12 | { | |
13 | long r; | |
14 | unsigned n; | |
15 | int fd; | |
16 | ||
17 | fd = open("/dev/urandom", O_RDONLY); | |
18 | while (length > 0) { | |
19 | ||
20 | if (!fd || read(fd, &r, sizeof(long)) != -1) <<<< the condition is | |
21 | incorrect | |
22 | --- | |
23 | usr/auth.c | 8 ++++---- | |
24 | 1 file changed, 4 insertions(+), 4 deletions(-) | |
25 | ||
26 | diff --git a/usr/auth.c b/usr/auth.c | |
27 | index c924545..4ff0425 100644 | |
28 | --- a/usr/auth.c | |
29 | +++ b/usr/auth.c | |
30 | @@ -189,24 +189,24 @@ get_random_bytes(unsigned char *data, unsigned int length) | |
31 | ||
32 | long r; | |
33 | unsigned n; | |
34 | - int fd; | |
35 | + int fd, r_size = sizeof(r); | |
36 | ||
37 | fd = open("/dev/urandom", O_RDONLY); | |
38 | while (length > 0) { | |
39 | ||
40 | - if (!fd || read(fd, &r, sizeof(long)) != -1) | |
41 | + if (fd == -1 || read(fd, &r, r_size) != r_size) | |
42 | r = rand(); | |
43 | r = r ^ (r >> 8); | |
44 | r = r ^ (r >> 4); | |
45 | n = r & 0x7; | |
46 | ||
47 | - if (!fd || read(fd, &r, sizeof(long)) != -1) | |
48 | + if (fd == -1 || read(fd, &r, r_size) != r_size) | |
49 | r = rand(); | |
50 | r = r ^ (r >> 8); | |
51 | r = r ^ (r >> 5); | |
52 | n = (n << 3) | (r & 0x7); | |
53 | ||
54 | - if (!fd || read(fd, &r, sizeof(long)) != -1) | |
55 | + if (fd == -1 || read(fd, &r, r_size) != r_size) | |
56 | r = rand(); | |
57 | r = r ^ (r >> 8); | |
58 | r = r ^ (r >> 5); | |
59 | -- | |
60 | 1.7.11.7 | |
61 |