RT4047: Set reference count earlier
authorFilipe DA SILVA <fdasilvaYY@gmail.com>
Thu, 17 Sep 2015 02:25:31 +0000 (22:25 -0400)
committerRich Salz <rsalz@openssl.org>
Thu, 17 Sep 2015 15:58:24 +0000 (11:58 -0400)
Make sure it's valid very early.

Signed-off-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/asn1/x_pkey.c
ssl/ssl_cert.c
ssl/ssl_lib.c

index 0665aab62251256b74530b8b7552e7279456b5cd..961b913dc9f1ad6418bb42cf3482f925ccc402f1 100644 (file)
@@ -70,11 +70,12 @@ X509_PKEY *X509_PKEY_new(void)
     if (!ret)
         goto err;
 
+    ret->references = 1;
     ret->enc_algor = X509_ALGOR_new();
     ret->enc_pkey = ASN1_OCTET_STRING_new();
     if (!ret->enc_algor || !ret->enc_pkey)
         goto err;
-    ret->references = 1;
+
     return ret;
 err:
     X509_PKEY_free(ret);
index 05a444745059980ec67abe3c33ecd7aa3fefdfbc..ecef7bddc859d01782928908c77ca790066d7cbc 100644 (file)
@@ -192,6 +192,7 @@ CERT *ssl_cert_dup(CERT *cert)
         return (NULL);
     }
 
+    ret->references = 1;
     ret->key = &ret->pkeys[cert->key - cert->pkeys];
 
 #ifndef OPENSSL_NO_RSA
@@ -278,7 +279,6 @@ CERT *ssl_cert_dup(CERT *cert)
         }
     }
 
-    ret->references = 1;
     /* Configured sigalgs copied across */
     if (cert->conf_sigalgs) {
         ret->conf_sigalgs = OPENSSL_malloc(cert->conf_sigalgslen);
index 28b71082ab37b54dd1578b135e9c8d6a2c7bec7c..e794d820585bb11b7d1f3bd065d41b9192ed0a38 100644 (file)
@@ -286,6 +286,7 @@ SSL *SSL_new(SSL_CTX *ctx)
     s->options = ctx->options;
     s->mode = ctx->mode;
     s->max_cert_list = ctx->max_cert_list;
+    s->references = 1;
 
     /*
      * Earlier library versions used to copy the pointer to the CERT, not
@@ -372,7 +373,6 @@ SSL *SSL_new(SSL_CTX *ctx)
     if (!s->method->ssl_new(s))
         goto err;
 
-    s->references = 1;
     s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;
 
     if (!SSL_clear(s))