BN_rand_range() needs a BN_rand() variant that doesn't set the MSB.
[openssl.git] / ssl / ssl_cert.c
index 7579a3432d92a13f60de98ddecb46db817216927..85d58c86688a454dd09da025b5dfdb0da8fae2c2 100644 (file)
 
 int SSL_get_ex_data_X509_STORE_CTX_idx(void)
        {
-       static int ssl_x509_store_ctx_idx= -1;
+       static volatile int ssl_x509_store_ctx_idx= -1;
 
        if (ssl_x509_store_ctx_idx < 0)
                {
-               ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
-                       0,"SSL for verify callback",NULL,NULL,NULL);
+               /* any write lock will do; usually this branch
+                * will only be taken once anyway */
+               CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
+               
+               if (ssl_x509_store_ctx_idx < 0)
+                       {
+                       ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
+                               0,"SSL for verify callback",NULL,NULL,NULL);
+                       }
+               
+               CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
                }
-       return(ssl_x509_store_ctx_idx);
+       return ssl_x509_store_ctx_idx;
        }
 
 CERT *ssl_cert_new(void)
@@ -271,7 +280,9 @@ CERT *ssl_cert_dup(CERT *cert)
 
        return(ret);
        
+#ifndef NO_DH /* avoid 'unreferenced label' warning if NO_DH is defined */
 err:
+#endif
 #ifndef NO_RSA
        if (ret->rsa_tmp != NULL)
                RSA_free(ret->rsa_tmp);
@@ -449,13 +460,15 @@ int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
        if (SSL_get_verify_depth(s) >= 0)
                X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
        X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s);
+
        /* We need to set the verify purpose. The purpose can be determined by
         * the context: if its a server it will verify SSL client certificates
         * or vice versa.
-         */
-
-       if(s->server) i = X509_PURPOSE_SSL_CLIENT;
-       else i = X509_PURPOSE_SSL_SERVER;
+        */
+       if (s->server)
+               i = X509_PURPOSE_SSL_CLIENT;
+       else
+               i = X509_PURPOSE_SSL_SERVER;
 
        X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust);
 
@@ -589,7 +602,7 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file)
        X509_NAME *xn=NULL;
        STACK_OF(X509_NAME) *ret,*sk;
 
-       ret=sk_X509_NAME_new(NULL);
+       ret=sk_X509_NAME_new_null();
        sk=sk_X509_NAME_new(xname_cmp);
 
        in=BIO_new(BIO_s_file_internal());