In asn1_d2i_read_bio, don't assume BIO_read will
[openssl.git] / ssl / s3_srvr.c
index 7742f3b8bc03d918e0811f4fed445e246d5eca84..3db3e78d5e1d50778adf8db21e40c72cc5eb452e 100644 (file)
  * The Contribution is licensed pursuant to the OpenSSL open source
  * license provided above.
  *
- * In addition, Sun covenants to all licensees who provide a reciprocal
- * covenant with respect to their own patents if any, not to sue under
- * current and future patent claims necessarily infringed by the making,
- * using, practicing, selling, offering for sale and/or otherwise
- * disposing of the Contribution as delivered hereunder 
- * (or portions thereof), provided that such covenant shall not apply:
- *  1) for code that a licensee deletes from the Contribution;
- *  2) separates from the Contribution; or
- *  3) for infringements caused by:
- *       i) the modification of the Contribution or
- *      ii) the combination of the  Contribution with other software or
- *          devices where such combination causes the infringement.
- *
  * ECC cipher suite support in OpenSSL originally written by
  * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
  *
@@ -183,12 +170,15 @@ SSL_METHOD *SSLv3_server_method(void)
                {
                CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD);
 
-               memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
-                       sizeof(SSL_METHOD));
-               SSLv3_server_data.ssl_accept=ssl3_accept;
-               SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
-               init=0;
-
+               if (init)
+                       {
+                       memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
+                               sizeof(SSL_METHOD));
+                       SSLv3_server_data.ssl_accept=ssl3_accept;
+                       SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
+                       init=0;
+                       }
+                       
                CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD);
                }
        return(&SSLv3_server_data);
@@ -1359,7 +1349,7 @@ static int ssl3_send_server_key_exchange(SSL *s)
                        kn=0;
                        }
 
-               if (!BUF_MEM_grow(buf,n+4+kn))
+               if (!BUF_MEM_grow_clean(buf,n+4+kn))
                        {
                        SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);
                        goto err;
@@ -1532,7 +1522,7 @@ static int ssl3_send_certificate_request(SSL *s)
                                {
                                name=sk_X509_NAME_value(sk,i);
                                j=i2d_X509_NAME(name,NULL);
-                               if (!BUF_MEM_grow(buf,4+n+j+2))
+                               if (!BUF_MEM_grow_clean(buf,4+n+j+2))
                                        {
                                        SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB);
                                        goto err;
@@ -1727,7 +1717,7 @@ static int ssl3_get_client_key_exchange(SSL *s)
                        s->method->ssl3_enc->generate_master_secret(s,
                                s->session->master_key,
                                p,i);
-               memset(p,0,i);
+               OPENSSL_cleanse(p,i);
                }
        else
 #endif
@@ -1790,7 +1780,7 @@ static int ssl3_get_client_key_exchange(SSL *s)
                s->session->master_key_length=
                        s->method->ssl3_enc->generate_master_secret(s,
                                s->session->master_key,p,i);
-               memset(p,0,i);
+               OPENSSL_cleanse(p,i);
                }
        else
 #endif
@@ -1893,7 +1883,7 @@ static int ssl3_get_client_key_exchange(SSL *s)
                 if (enc == NULL)
                     goto err;
 
-               memset(iv, 0, EVP_MAX_IV_LENGTH);       /* per RFC 1510 */
+               memset(iv, 0, sizeof iv);       /* per RFC 1510 */
 
                if (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv))
                        {
@@ -2079,7 +2069,7 @@ static int ssl3_get_client_key_exchange(SSL *s)
                 s->session->master_key_length = s->method->ssl3_enc-> \
                    generate_master_secret(s, s->session->master_key, p, i);
                
-                memset(p, 0, i);
+                OPENSSL_cleanse(p, i);
                 return (ret);
                }
        else
@@ -2097,7 +2087,7 @@ f_err:
 #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH)
 err:
 #endif
-#ifndef NO_OPENSSL_ECDH
+#ifndef OPENSSL_NO_ECDH
        EVP_PKEY_free(clnt_pub_pkey);
        EC_POINT_free(clnt_ecpoint);
        if (srvr_ecdh != NULL) 
@@ -2124,7 +2114,7 @@ static int ssl3_get_cert_verify(SSL *s)
                SSL3_ST_SR_CERT_VRFY_A,
                SSL3_ST_SR_CERT_VRFY_B,
                -1,
-               512, /* 512? */
+               514, /* 514? */
                &ok);
 
        if (!ok) return((int)n);