[Pkg-iscsi-maintainers] [open-iscsi] 10/33: iscsi tools: fix get_random_bytes error handling

Ritesh Raj Sarraf rrs at alioth.debian.org
Tue Nov 5 16:21:12 UTC 2013


This is an automated email from the git hooks/post-receive script.

rrs pushed a commit to branch upstream-mnc
in repository open-iscsi.

commit a7afdf46c3193eb102cc6ec2a3b61e8d36794437
Author: Mike Christie <michaelc at cs.wisc.edu>
Date:   Fri Dec 14 12:40:27 2012 -0600

    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
---
 usr/auth.c |    8 ++++----
 1 file 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-iscsi/open-iscsi.git



More information about the Pkg-iscsi-maintainers mailing list