summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-08-10 15:05:28 +0000
committertb <>2023-08-10 15:05:28 +0000
commit3c2cb2633347857266edec5c36b278a2eb7b13fd (patch)
tree8d1950a42e00bbb98113c6eda16f45e77cfa2388
parent6f0e5d3e4213fc2ec901d65902fbeb0a59c05fad (diff)
downloadopenbsd-3c2cb2633347857266edec5c36b278a2eb7b13fd.tar.gz
openbsd-3c2cb2633347857266edec5c36b278a2eb7b13fd.tar.bz2
openbsd-3c2cb2633347857266edec5c36b278a2eb7b13fd.zip
Fix a leak in rsa_pub_encode()
rsa_param_encode() allocates the PSS parameters in an ASN1_STRING which is leaked if any error occurs later in rsa_pub_encode(). Convert the rest of the code to follow our ordinary idioms more closely. ok jsing
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index 737bba7366..46837881ed 100644
--- a/src/lib/libcrypto/rsa/rsa_ameth.c
+++ b/src/lib/libcrypto/rsa/rsa_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_ameth.c,v 1.31 2023/08/10 09:36:37 tb Exp $ */ 1/* $OpenBSD: rsa_ameth.c,v 1.32 2023/08/10 15:05:28 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 */
@@ -136,21 +136,28 @@ rsa_param_decode(RSA *rsa, const X509_ALGOR *alg)
136static int 136static int
137rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) 137rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
138{ 138{
139 unsigned char *penc = NULL; 139 ASN1_STRING *str = NULL;
140 int penclen;
141 ASN1_STRING *str;
142 int strtype; 140 int strtype;
141 unsigned char *penc = NULL;
142 int penclen = 0;
143 ASN1_OBJECT *aobj;
143 144
144 if (!rsa_param_encode(pkey, &str, &strtype)) 145 if (!rsa_param_encode(pkey, &str, &strtype))
145 return 0; 146 goto err;
146 penclen = i2d_RSAPublicKey(pkey->pkey.rsa, &penc); 147 if ((penclen = i2d_RSAPublicKey(pkey->pkey.rsa, &penc)) <= 0) {
147 if (penclen <= 0) 148 penclen = 0;
148 return 0; 149 goto err;
149 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(pkey->ameth->pkey_id), 150 }
150 strtype, str, penc, penclen)) 151 if ((aobj = OBJ_nid2obj(pkey->ameth->pkey_id)) == NULL)
151 return 1; 152 goto err;
153 if (!X509_PUBKEY_set0_param(pk, aobj, strtype, str, penc, penclen))
154 goto err;
152 155
153 free(penc); 156 return 1;
157
158 err:
159 ASN1_STRING_free(str);
160 freezero(penc, penclen);
154 161
155 return 0; 162 return 0;
156} 163}