summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/pmeth_gn.c
diff options
context:
space:
mode:
authortb <>2024-04-17 08:24:11 +0000
committertb <>2024-04-17 08:24:11 +0000
commit23380829ee38bf67638fa510aebf161b5cc21015 (patch)
treec044d2370e7f82e20f6641ca7dc7e45186913023 /src/lib/libcrypto/evp/pmeth_gn.c
parent54dc7a747ab7cbf6d90edf6ba3ad028a0d231205 (diff)
downloadopenbsd-23380829ee38bf67638fa510aebf161b5cc21015.tar.gz
openbsd-23380829ee38bf67638fa510aebf161b5cc21015.tar.bz2
openbsd-23380829ee38bf67638fa510aebf161b5cc21015.zip
Avoid NULL dereference in EVP_PKEY_paramgen()
If EVP_PKEY_new() returns NULL, it would be passed to the paramgen() pmeth which would typically dereference it. This is identical to a recent change in keygen(). ok jsing
Diffstat (limited to 'src/lib/libcrypto/evp/pmeth_gn.c')
-rw-r--r--src/lib/libcrypto/evp/pmeth_gn.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/libcrypto/evp/pmeth_gn.c b/src/lib/libcrypto/evp/pmeth_gn.c
index b8b51ced3d..1c355e594a 100644
--- a/src/lib/libcrypto/evp/pmeth_gn.c
+++ b/src/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_gn.c,v 1.18 2024/04/12 09:41:39 tb Exp $ */ 1/* $OpenBSD: pmeth_gn.c,v 1.19 2024/04/17 08:24:11 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 */
@@ -87,7 +87,7 @@ EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
87{ 87{
88 int ret; 88 int ret;
89 89
90 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) { 90 if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->paramgen == NULL) {
91 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); 91 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
92 return -2; 92 return -2;
93 } 93 }
@@ -97,17 +97,19 @@ EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
97 return -1; 97 return -1;
98 } 98 }
99 99
100 if (!ppkey) 100 if (ppkey == NULL)
101 return -1; 101 return -1;
102 102
103 if (!*ppkey) 103 if (*ppkey == NULL)
104 *ppkey = EVP_PKEY_new(); 104 *ppkey = EVP_PKEY_new();
105 if (*ppkey == NULL)
106 return -1;
105 107
106 ret = ctx->pmeth->paramgen(ctx, *ppkey); 108 if ((ret = ctx->pmeth->paramgen(ctx, *ppkey)) <= 0) {
107 if (ret <= 0) {
108 EVP_PKEY_free(*ppkey); 109 EVP_PKEY_free(*ppkey);
109 *ppkey = NULL; 110 *ppkey = NULL;
110 } 111 }
112
111 return ret; 113 return ret;
112} 114}
113LCRYPTO_ALIAS(EVP_PKEY_paramgen); 115LCRYPTO_ALIAS(EVP_PKEY_paramgen);