summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortedu <>2014-06-30 14:15:34 +0000
committertedu <>2014-06-30 14:15:34 +0000
commit948e49c9c38464c823ba12a3f493cc7f8df7e73f (patch)
treefcbe2692249123c069961e58bc924b1ff30dbbf1 /src
parent9212388050af9e43bf2dc3b5be5f0e702bdb4587 (diff)
downloadopenbsd-948e49c9c38464c823ba12a3f493cc7f8df7e73f.tar.gz
openbsd-948e49c9c38464c823ba12a3f493cc7f8df7e73f.tar.bz2
openbsd-948e49c9c38464c823ba12a3f493cc7f8df7e73f.zip
simplify and unobfuscate a variable to fix a mem leak.
original diff by logan
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/dh/dh_ameth.c15
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_ameth.c15
2 files changed, 18 insertions, 12 deletions
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c
index 9683a294dc..88ef78d98d 100644
--- a/src/lib/libcrypto/dh/dh_ameth.c
+++ b/src/lib/libcrypto/dh/dh_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_ameth.c,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */ 1/* $OpenBSD: dh_ameth.c,v 1.8 2014/06/30 14:15:34 tedu Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -130,7 +130,6 @@ static int dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
130static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) 130static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
131 { 131 {
132 DH *dh; 132 DH *dh;
133 void *pval = NULL;
134 int ptype; 133 int ptype;
135 unsigned char *penc = NULL; 134 unsigned char *penc = NULL;
136 int penclen; 135 int penclen;
@@ -140,13 +139,17 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
140 dh=pkey->pkey.dh; 139 dh=pkey->pkey.dh;
141 140
142 str = ASN1_STRING_new(); 141 str = ASN1_STRING_new();
142 if (str == NULL) {
143 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
144 goto err;
145 }
146
143 str->length = i2d_DHparams(dh, &str->data); 147 str->length = i2d_DHparams(dh, &str->data);
144 if (str->length <= 0) 148 if (str->length <= 0)
145 { 149 {
146 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 150 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
147 goto err; 151 goto err;
148 } 152 }
149 pval = str;
150 ptype = V_ASN1_SEQUENCE; 153 ptype = V_ASN1_SEQUENCE;
151 154
152 pub_key = BN_to_ASN1_INTEGER(dh->pub_key, NULL); 155 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)
164 } 167 }
165 168
166 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DH), 169 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DH),
167 ptype, pval, penc, penclen)) 170 ptype, (void *)str, penc, penclen))
168 return 1; 171 return 1;
169 172
170 err: 173 err:
171 free(penc); 174 free(penc);
172 if (pval) 175 if (str)
173 ASN1_STRING_free(pval); 176 ASN1_STRING_free(str);
174 177
175 return 0; 178 return 0;
176 } 179 }
diff --git a/src/lib/libssl/src/crypto/dh/dh_ameth.c b/src/lib/libssl/src/crypto/dh/dh_ameth.c
index 9683a294dc..88ef78d98d 100644
--- a/src/lib/libssl/src/crypto/dh/dh_ameth.c
+++ b/src/lib/libssl/src/crypto/dh/dh_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_ameth.c,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */ 1/* $OpenBSD: dh_ameth.c,v 1.8 2014/06/30 14:15:34 tedu Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -130,7 +130,6 @@ static int dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
130static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) 130static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
131 { 131 {
132 DH *dh; 132 DH *dh;
133 void *pval = NULL;
134 int ptype; 133 int ptype;
135 unsigned char *penc = NULL; 134 unsigned char *penc = NULL;
136 int penclen; 135 int penclen;
@@ -140,13 +139,17 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
140 dh=pkey->pkey.dh; 139 dh=pkey->pkey.dh;
141 140
142 str = ASN1_STRING_new(); 141 str = ASN1_STRING_new();
142 if (str == NULL) {
143 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
144 goto err;
145 }
146
143 str->length = i2d_DHparams(dh, &str->data); 147 str->length = i2d_DHparams(dh, &str->data);
144 if (str->length <= 0) 148 if (str->length <= 0)
145 { 149 {
146 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 150 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
147 goto err; 151 goto err;
148 } 152 }
149 pval = str;
150 ptype = V_ASN1_SEQUENCE; 153 ptype = V_ASN1_SEQUENCE;
151 154
152 pub_key = BN_to_ASN1_INTEGER(dh->pub_key, NULL); 155 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)
164 } 167 }
165 168
166 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DH), 169 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DH),
167 ptype, pval, penc, penclen)) 170 ptype, (void *)str, penc, penclen))
168 return 1; 171 return 1;
169 172
170 err: 173 err:
171 free(penc); 174 free(penc);
172 if (pval) 175 if (str)
173 ASN1_STRING_free(pval); 176 ASN1_STRING_free(str);
174 177
175 return 0; 178 return 0;
176 } 179 }