summaryrefslogtreecommitdiff
path: root/src/common/tortls.c
diff options
context:
space:
mode:
authorMarek Majkowski <marek@popcount.org>2013-06-06 12:45:25 +0100
committerMarek Majkowski <marek@popcount.org>2013-06-06 12:45:25 +0100
commita022930fda028aaf04c33eba3b3ae0f85f22526b (patch)
tree6ae6448ce40d0a7eff74d9805d268abcdcdfe120 /src/common/tortls.c
parent6f1c67195c6a477d16d9ef7a97bd2da86fdfd225 (diff)
downloadtor-a022930fda028aaf04c33eba3b3ae0f85f22526b.tar.gz
tor-a022930fda028aaf04c33eba3b3ae0f85f22526b.zip
Bug #5170 - simplify i2d_X509
Diffstat (limited to 'src/common/tortls.c')
-rw-r--r--src/common/tortls.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c
index b7e5bc1a5f..0773068a44 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -806,24 +806,24 @@ tor_cert_new(X509 *x509_cert)
tor_cert_t *cert;
EVP_PKEY *pkey;
RSA *rsa;
- int length, length2;
- unsigned char *cp;
+ int length;
+ unsigned char *buf = NULL;
if (!x509_cert)
return NULL;
- length = i2d_X509(x509_cert, NULL);
+ length = i2d_X509(x509_cert, &buf);
cert = tor_malloc_zero(sizeof(tor_cert_t));
- if (length <= 0) {
+ if (length <= 0 || buf == NULL) {
tor_free(cert);
log_err(LD_CRYPTO, "Couldn't get length of encoded x509 certificate");
X509_free(x509_cert);
return NULL;
}
cert->encoded_len = (size_t) length;
- cp = cert->encoded = tor_malloc(length);
- length2 = i2d_X509(x509_cert, &cp);
- tor_assert(length2 == length);
+ cert->encoded = tor_malloc(length);
+ memcpy(cert->encoded, buf, length);
+ OPENSSL_free(buf);
cert->cert = x509_cert;