summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-06-30 14:15:35 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-06-30 14:15:35 +0000
commit4ad90748a04d28c38131c3276485fcf89a9f1fb6 (patch)
tree9f724820427ec794876e40eccacbf7812f652a63
parentab6cfbd8bd550bc937188a8b31032498a7591abd (diff)
simplify and unobfuscate a variable to fix a mem leak.
original diff by logan
-rw-r--r--lib/libssl/src/crypto/dh/dh_ameth.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libssl/src/crypto/dh/dh_ameth.c b/lib/libssl/src/crypto/dh/dh_ameth.c
index 9683a294dc3..88ef78d98d1 100644
--- a/lib/libssl/src/crypto/dh/dh_ameth.c
+++ b/lib/libssl/src/crypto/dh/dh_ameth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dh_ameth.c,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */
+/* $OpenBSD: dh_ameth.c,v 1.8 2014/06/30 14:15:34 tedu Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -130,7 +130,6 @@ static int dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
{
DH *dh;
- void *pval = NULL;
int ptype;
unsigned char *penc = NULL;
int penclen;
@@ -140,13 +139,17 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
dh=pkey->pkey.dh;
str = ASN1_STRING_new();
+ if (str == NULL) {
+ DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
str->length = i2d_DHparams(dh, &str->data);
if (str->length <= 0)
{
DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
goto err;
}
- pval = str;
ptype = V_ASN1_SEQUENCE;
pub_key = BN_to_ASN1_INTEGER(dh->pub_key, NULL);
@@ -164,13 +167,13 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
}
if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DH),
- ptype, pval, penc, penclen))
+ ptype, (void *)str, penc, penclen))
return 1;
err:
free(penc);
- if (pval)
- ASN1_STRING_free(pval);
+ if (str)
+ ASN1_STRING_free(str);
return 0;
}