diff options
author | tb <> | 2024-04-12 02:56:15 +0000 |
---|---|---|
committer | tb <> | 2024-04-12 02:56:15 +0000 |
commit | dda4678a08f6ff49cde7fbf6544bb429119ec956 (patch) | |
tree | 5218b54e3c8499f591e0fff73f6ab77a4d016631 /src | |
parent | e18ebbb1a24e04f2cd7c015bb5fb10c7140c35ab (diff) | |
download | openbsd-dda4678a08f6ff49cde7fbf6544bb429119ec956.tar.gz openbsd-dda4678a08f6ff49cde7fbf6544bb429119ec956.tar.bz2 openbsd-dda4678a08f6ff49cde7fbf6544bb429119ec956.zip |
Fix a potential NULL-deref in EVP_PKEY_keygen()
After a EVP_PKEY_new() failure, a NULL pointer would be passed to the
keygen pmeth, which could result in tears.
ok beck jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/evp/pmeth_gn.c | 14 |
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 2711ba1a9e..b86ecc6811 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.16 2024/04/09 13:52:41 beck Exp $ */ | 1 | /* $OpenBSD: pmeth_gn.c,v 1.17 2024/04/12 02:56:15 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 | */ |
@@ -141,7 +141,7 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) | |||
141 | { | 141 | { |
142 | int ret; | 142 | int ret; |
143 | 143 | ||
144 | if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) { | 144 | if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->keygen == NULL) { |
145 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 145 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
146 | return -2; | 146 | return -2; |
147 | } | 147 | } |
@@ -150,17 +150,19 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) | |||
150 | return -1; | 150 | return -1; |
151 | } | 151 | } |
152 | 152 | ||
153 | if (!ppkey) | 153 | if (ppkey == NULL) |
154 | return -1; | 154 | return -1; |
155 | 155 | ||
156 | if (!*ppkey) | 156 | if (*ppkey == NULL) |
157 | *ppkey = EVP_PKEY_new(); | 157 | *ppkey = EVP_PKEY_new(); |
158 | if (*ppkey == NULL) | ||
159 | return -1; | ||
158 | 160 | ||
159 | ret = ctx->pmeth->keygen(ctx, *ppkey); | 161 | if ((ret = ctx->pmeth->keygen(ctx, *ppkey)) <= 0) { |
160 | if (ret <= 0) { | ||
161 | EVP_PKEY_free(*ppkey); | 162 | EVP_PKEY_free(*ppkey); |
162 | *ppkey = NULL; | 163 | *ppkey = NULL; |
163 | } | 164 | } |
165 | |||
164 | return ret; | 166 | return ret; |
165 | } | 167 | } |
166 | LCRYPTO_ALIAS(EVP_PKEY_keygen); | 168 | LCRYPTO_ALIAS(EVP_PKEY_keygen); |