From dc6132822b5299d3185756c88e49231463ef8732 Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 28 Dec 2023 21:57:08 +0000 Subject: [PATCH] Clean up old_rsa_priv_decode() Again change this function into the single exit idiom, and error check EVP_PKEY_assign(). ok jsing --- lib/libcrypto/rsa/rsa_ameth.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/libcrypto/rsa/rsa_ameth.c b/lib/libcrypto/rsa/rsa_ameth.c index 228793b05c9..b2f6b2f79b8 100644 --- a/lib/libcrypto/rsa/rsa_ameth.c +++ b/lib/libcrypto/rsa/rsa_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_ameth.c,v 1.51 2023/11/09 08:29:53 tb Exp $ */ +/* $OpenBSD: rsa_ameth.c,v 1.52 2023/12/28 21:57:08 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -204,13 +204,22 @@ static int old_rsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) { RSA *rsa; + int ret = 0; if ((rsa = d2i_RSAPrivateKey(NULL, pder, derlen)) == NULL) { RSAerror(ERR_R_RSA_LIB); - return 0; + goto err; } - EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa); - return 1; + if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa)) + goto err; + rsa = NULL; + + ret = 1; + + err: + RSA_free(rsa); + + return ret; } static int -- 2.20.1