summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dh
diff options
context:
space:
mode:
authortb <>2023-08-12 07:50:47 +0000
committertb <>2023-08-12 07:50:47 +0000
commit75d00cb38a793e674ec61e79cfad30c174e5a93c (patch)
treed4bb9a302e2a9007c4e03757faff7454de03ec43 /src/lib/libcrypto/dh
parent3ce61e18114b54d6a68b3d52d58caecbb472fe23 (diff)
downloadopenbsd-75d00cb38a793e674ec61e79cfad30c174e5a93c.tar.gz
openbsd-75d00cb38a793e674ec61e79cfad30c174e5a93c.tar.bz2
openbsd-75d00cb38a793e674ec61e79cfad30c174e5a93c.zip
Free {priv,pub}_key before assigning to it
While it isn't the case for the default implementations, custom DH and DSA methods could conceivably populate private and public keys, which in turn would result in leaks in the pub/priv decode methods. ok jsing
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r--src/lib/libcrypto/dh/dh_ameth.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c
index 88fec6bf4a..ec9fe43d2b 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.37 2023/08/12 07:43:48 tb Exp $ */ 1/* $OpenBSD: dh_ameth.c,v 1.38 2023/08/12 07:50:47 tb 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 */
@@ -111,6 +111,7 @@ dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
111 DHerror(DH_R_DECODE_ERROR); 111 DHerror(DH_R_DECODE_ERROR);
112 goto err; 112 goto err;
113 } 113 }
114 BN_free(dh->pub_key);
114 if ((dh->pub_key = ASN1_INTEGER_to_BN(aint, NULL)) == NULL) { 115 if ((dh->pub_key = ASN1_INTEGER_to_BN(aint, NULL)) == NULL) {
115 DHerror(DH_R_BN_DECODE_ERROR); 116 DHerror(DH_R_BN_DECODE_ERROR);
116 goto err; 117 goto err;
@@ -223,6 +224,7 @@ dh_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
223 DHerror(DH_R_DECODE_ERROR); 224 DHerror(DH_R_DECODE_ERROR);
224 goto err; 225 goto err;
225 } 226 }
227 BN_free(dh->priv_key);
226 if ((dh->priv_key = ASN1_INTEGER_to_BN(aint, NULL)) == NULL) { 228 if ((dh->priv_key = ASN1_INTEGER_to_BN(aint, NULL)) == NULL) {
227 DHerror(DH_R_BN_DECODE_ERROR); 229 DHerror(DH_R_BN_DECODE_ERROR);
228 goto err; 230 goto err;