summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-04-12 02:56:16 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-04-12 02:56:16 +0000
commit8bc51c5fdebfa3deac4c023efaef7d78b41f62f3 (patch)
tree7da207a58072fe19dcd4f08068f72727cedb30b1 /lib
parent3d04f66f5317d4f58312c9dcb6e15ebf0eff6c9d (diff)
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 'lib')
-rw-r--r--lib/libcrypto/evp/pmeth_gn.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/libcrypto/evp/pmeth_gn.c b/lib/libcrypto/evp/pmeth_gn.c
index 2711ba1a9e8..b86ecc68113 100644
--- a/lib/libcrypto/evp/pmeth_gn.c
+++ b/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmeth_gn.c,v 1.16 2024/04/09 13:52:41 beck Exp $ */
+/* $OpenBSD: pmeth_gn.c,v 1.17 2024/04/12 02:56:15 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@@ -141,7 +141,7 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
{
int ret;
- if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
+ if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->keygen == NULL) {
EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
return -2;
}
@@ -150,17 +150,19 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
return -1;
}
- if (!ppkey)
+ if (ppkey == NULL)
return -1;
- if (!*ppkey)
+ if (*ppkey == NULL)
*ppkey = EVP_PKEY_new();
+ if (*ppkey == NULL)
+ return -1;
- ret = ctx->pmeth->keygen(ctx, *ppkey);
- if (ret <= 0) {
+ if ((ret = ctx->pmeth->keygen(ctx, *ppkey)) <= 0) {
EVP_PKEY_free(*ppkey);
*ppkey = NULL;
}
+
return ret;
}
LCRYPTO_ALIAS(EVP_PKEY_keygen);