From ab5a172f1b41b12133b95822d5bf004c322965cb Mon Sep 17 00:00:00 2001 From: zhailiangliang Date: Wed, 15 Feb 2023 10:43:01 +0800 Subject: Fix potential NULL pointer dereference in function evp_pkey_asn1_ctrl CLA: trivial Reviewed-by: Hugo Landau Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/20294) --- crypto/evp/p_lib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crypto') diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 905e9c9ce4..554fad927c 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -1324,6 +1324,8 @@ static int evp_pkey_asn1_ctrl(EVP_PKEY *pkey, int op, int arg1, void *arg2) int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid) { + if (pkey == NULL) + return 0; return evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, 0, pnid); } @@ -1374,7 +1376,9 @@ int EVP_PKEY_digestsign_supports_digest(EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey, const unsigned char *pub, size_t publen) { - if (pkey != NULL && evp_pkey_is_provided(pkey)) + if (pkey == NULL) + return 0; + if (evp_pkey_is_provided(pkey)) return EVP_PKEY_set_octet_string_param(pkey, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, @@ -1393,7 +1397,9 @@ size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub) { int rv; - if (pkey != NULL && evp_pkey_is_provided(pkey)) { + if (pkey == NULL) + return 0; + if (evp_pkey_is_provided(pkey)) { size_t return_size = OSSL_PARAM_UNMODIFIED; unsigned char *buf; -- cgit v1.2.3