[tor-commits] [tor/master] Fix some more issues wrt tor_cert_new found by asn

nickm at torproject.org nickm at torproject.org
Tue Oct 11 03:22:16 UTC 2011


commit 40f0d111c2263b44d30d47a292b3bb9ef3a01a08
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Oct 5 10:25:42 2011 -0400

    Fix some more issues wrt tor_cert_new found by asn
---
 src/common/tortls.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/common/tortls.c b/src/common/tortls.c
index 206ac3b..247e9ee 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -706,9 +706,13 @@ tor_cert_new(X509 *x509_cert)
   tor_cert_t *cert;
   EVP_PKEY *pkey;
   RSA *rsa;
-  int length = i2d_X509(x509_cert, NULL), length2;
+  int length, length2;
   unsigned char *cp;
 
+  if (!x509_cert)
+    return NULL;
+
+  length = i2d_X509(x509_cert, NULL);
   cert = tor_malloc_zero(sizeof(tor_cert_t));
   if (length <= 0) {
     tor_free(cert);
@@ -766,7 +770,6 @@ tor_cert_decode(const uint8_t *certificate, size_t certificate_len)
   }
   newcert = tor_cert_new(x509);
   if (!newcert) {
-    X509_free(x509);
     return NULL;
   }
   if (newcert->encoded_len != certificate_len ||
@@ -1118,6 +1121,8 @@ tor_tls_context_new(crypto_pk_env_t *identity, unsigned int key_lifetime)
   result->my_link_cert = tor_cert_new(X509_dup(cert));
   result->my_id_cert = tor_cert_new(X509_dup(idcert));
   result->my_auth_cert = tor_cert_new(X509_dup(authcert));
+  if (!result->my_link_cert || !result->my_id_cert || !result->my_auth_cert)
+    goto error;
   result->link_key = crypto_pk_dup_key(rsa);
   result->auth_key = crypto_pk_dup_key(rsa_auth);
 





More information about the tor-commits mailing list