Fix CID 1466712 : Resource leak in ec_kmgmt due to new callto ossl_prov_is_running()
authorShane Lontis <shane.lontis@oracle.com>
Mon, 21 Sep 2020 01:29:30 +0000 (11:29 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Wed, 23 Sep 2020 07:16:39 +0000 (17:16 +1000)
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12930)

providers/implementations/keymgmt/ec_kmgmt.c

index 1e32db1b6f678c69e202057ac222d5831d043d4e..63c51af3a1956c0334ad9a81220d3d178395725d 100644 (file)
@@ -276,12 +276,16 @@ static int ec_match(const void *keydata1, const void *keydata2, int selection)
     const EC_KEY *ec2 = keydata2;
     const EC_GROUP *group_a = EC_KEY_get0_group(ec1);
     const EC_GROUP *group_b = EC_KEY_get0_group(ec2);
-    BN_CTX *ctx = BN_CTX_new_ex(ec_key_get_libctx(ec1));
+    BN_CTX *ctx = NULL;
     int ok = 1;
 
     if (!ossl_prov_is_running())
         return 0;
 
+    ctx = BN_CTX_new_ex(ec_key_get_libctx(ec1));
+    if (ctx == NULL)
+        return 0;
+
     if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
         ok = ok && group_a != NULL && group_b != NULL
             && EC_GROUP_cmp(group_a, group_b, ctx) == 0;