check return value of RAND_pseudo_bytes; backport from the stable branch
authorNils Larsch <nils@openssl.org>
Fri, 29 Apr 2005 20:10:06 +0000 (20:10 +0000)
committerNils Larsch <nils@openssl.org>
Fri, 29 Apr 2005 20:10:06 +0000 (20:10 +0000)
ChangeLog.0_9_7-stable_not-in-head
ssl/s23_clnt.c
ssl/s2_clnt.c
ssl/s2_srvr.c
ssl/s3_clnt.c
ssl/s3_srvr.c
ssl/ssl_sess.c

index b2edc7f..7ecd4e6 100644 (file)
@@ -612,18 +612,6 @@ be added to the end of this file.
        All EVP_*_cfb functions have changed names to EVP_*_cfb64 or
        EVP_*_cfb128.
 
-2004-05-15 18:39  ben
-
-       Changed:
-               ssl/s23_clnt.c (1.20.2.6), "Exp", lines: +5 -2
-               ssl/s2_clnt.c (1.37.2.11), "Exp", lines: +5 -2
-               ssl/s2_srvr.c (1.36.2.8), "Exp", lines: +6 -3
-               ssl/s3_clnt.c (1.53.2.17), "Exp", lines: +2 -1
-               ssl/s3_srvr.c (1.85.2.22), "Exp", lines: +4 -2
-               ssl/ssl_sess.c (1.40.2.8), "Exp", lines: +2 -1
-
-       Check error returns.
-
 2004-05-17 06:39  levitte
 
        Changed:
index 64ee426..3384fb7 100644 (file)
@@ -235,7 +235,8 @@ static int ssl23_client_hello(SSL *s)
 #endif
 
                p=s->s3->client_random;
-               RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE);
+               if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE) <= 0)
+                       return -1;
 
                /* Do the message type and length last */
                d= &(buf[2]);
@@ -296,7 +297,9 @@ static int ssl23_client_hello(SSL *s)
                        i=ch_len;
                s2n(i,d);
                memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE);
-               RAND_pseudo_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
+               if (RAND_pseudo_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i) <= 0)
+                       return -1;
+
                memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
                p+=i;
 
index 77d8a3b..415cdab 100644 (file)
@@ -612,7 +612,8 @@ static int client_hello(SSL *s)
                s->s2->challenge_length=SSL2_CHALLENGE_LENGTH;
                s2n(SSL2_CHALLENGE_LENGTH,p);           /* challenge length */
                /*challenge id data*/
-               RAND_pseudo_bytes(s->s2->challenge,SSL2_CHALLENGE_LENGTH);
+               if (RAND_pseudo_bytes(s->s2->challenge,SSL2_CHALLENGE_LENGTH) <= 0)
+                       return -1;
                memcpy(d,s->s2->challenge,SSL2_CHALLENGE_LENGTH);
                d+=SSL2_CHALLENGE_LENGTH;
 
@@ -660,7 +661,9 @@ static int client_master_key(SSL *s)
                        SSLerr(SSL_F_CLIENT_MASTER_KEY, ERR_R_INTERNAL_ERROR);
                        return -1;
                        }
-               if (i > 0) RAND_pseudo_bytes(sess->key_arg,i);
+               if (i > 0)
+                       if (RAND_pseudo_bytes(sess->key_arg,i) <= 0)
+                               return -1;
 
                /* make a master key */
                i=EVP_CIPHER_key_length(c);
index 6c43f72..7cc160b 100644 (file)
@@ -498,7 +498,8 @@ static int get_client_master_key(SSL *s)
                        i=ek;
                else
                        i=EVP_CIPHER_key_length(c);
-               RAND_pseudo_bytes(p,i);
+               if (RAND_pseudo_bytes(p,i) <= 0)
+                       return 0;
                }
 #else
        if (i < 0)
@@ -804,7 +805,8 @@ static int server_hello(SSL *s)
                /* make and send conn_id */
                s2n(SSL2_CONNECTION_ID_LENGTH,p);       /* add conn_id length */
                s->s2->conn_id_length=SSL2_CONNECTION_ID_LENGTH;
-               RAND_pseudo_bytes(s->s2->conn_id,(int)s->s2->conn_id_length);
+               if (RAND_pseudo_bytes(s->s2->conn_id,(int)s->s2->conn_id_length) <= 0)
+                       return -1;
                memcpy(d,s->s2->conn_id,SSL2_CONNECTION_ID_LENGTH);
                d+=SSL2_CONNECTION_ID_LENGTH;
 
@@ -950,7 +952,8 @@ static int request_certificate(SSL *s)
                p=(unsigned char *)s->init_buf->data;
                *(p++)=SSL2_MT_REQUEST_CERTIFICATE;
                *(p++)=SSL2_AT_MD5_WITH_RSA_ENCRYPTION;
-               RAND_pseudo_bytes(ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);
+               if (RAND_pseudo_bytes(ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH) <= 0)
+                       return -1;
                memcpy(p,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);
 
                s->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_B;
index b40571d..fc376cb 100644 (file)
@@ -552,7 +552,8 @@ int ssl3_client_hello(SSL *s)
                p=s->s3->client_random;
                Time=time(NULL);                        /* Time */
                l2n(Time,p);
-               RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4);
+               if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+                       goto err;
 
                /* Do the message type and length last */
                d=p= &(buf[4]);
index b9ff631..7bb68e0 100644 (file)
@@ -1048,7 +1048,8 @@ int ssl3_send_server_hello(SSL *s)
                p=s->s3->server_random;
                Time=time(NULL);                        /* Time */
                l2n(Time,p);
-               RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4);
+               if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0)
+                       return -1;
                /* Do the message type and length last */
                d=p= &(buf[4]);
 
@@ -1784,7 +1785,8 @@ int ssl3_get_client_key_exchange(SSL *s)
                        i = SSL_MAX_MASTER_KEY_LENGTH;
                        p[0] = s->client_version >> 8;
                        p[1] = s->client_version & 0xff;
-                       RAND_pseudo_bytes(p+2, i-2); /* should be RAND_bytes, but we cannot work around a failure */
+                       if (RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */
+                               goto err;
                        }
        
                s->session->master_key_length=
index 6ca8083..5d00a98 100644 (file)
@@ -148,7 +148,8 @@ static int def_generate_session_id(const SSL *ssl, unsigned char *id,
 {
        unsigned int retry = 0;
        do
-               RAND_pseudo_bytes(id, *id_len);
+               if (RAND_pseudo_bytes(id, *id_len) <= 0)
+                       return 0;
        while(SSL_has_matching_session_id(ssl, id, *id_len) &&
                (++retry < MAX_SESS_ID_ATTEMPTS));
        if(retry < MAX_SESS_ID_ATTEMPTS)