Add checks for NULL return from EC_KEY_get0_group()

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13139)
This commit is contained in:
Tomas Mraz 2021-01-22 13:59:54 +01:00
parent f468e2f951
commit 82a4620091
2 changed files with 9 additions and 2 deletions

View File

@ -172,6 +172,9 @@ static int pkey_ec_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
if (!key) {
const EC_GROUP *group;
group = EC_KEY_get0_group(eckey);
if (group == NULL)
return 0;
*keylen = (EC_GROUP_get_degree(group) + 7) / 8;
return 1;
}

View File

@ -1221,9 +1221,11 @@ int EVP_PKEY_get_group_name(const EVP_PKEY *pkey, char *gname, size_t gname_sz,
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC:
{
EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
const EC_GROUP *grp = EC_KEY_get0_group(EVP_PKEY_get0_EC_KEY(pkey));
int nid = NID_undef;
if (grp != NULL)
nid = EC_GROUP_get_curve_name(grp);
if (nid != NID_undef)
name = ec_curve_nid2name(nid);
}
@ -2271,6 +2273,8 @@ int EVP_PKEY_get_field_type(const EVP_PKEY *pkey)
if (ec == NULL)
return 0;
grp = EC_KEY_get0_group(ec);
if (grp == NULL)
return 0;
return EC_GROUP_get_field_type(grp);
#else