Fix potential NULL dereference in ossl_ec_key_dup()
authorTomas Mraz <tomas@openssl.org>
Mon, 19 Apr 2021 13:50:35 +0000 (15:50 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 22 Apr 2021 14:46:20 +0000 (16:46 +0200)
Fixes Coverity ID 1476282

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14928)

crypto/ec/ec_backend.c

index e9843eb4ac73a196b51d9f621e53a238d4ca3ecd..581c006fd037d40b89a42fdec369038e87afeef2 100644 (file)
@@ -532,17 +532,17 @@ int ossl_ec_key_is_foreign(const EC_KEY *ec)
 
 EC_KEY *ossl_ec_key_dup(const EC_KEY *src, int selection)
 {
-    EC_KEY *ret = ossl_ec_key_new_method_int(src->libctx, src->propq,
-                                             src->engine);
-
-    if (ret == NULL)
-        return NULL;
+    EC_KEY *ret;
 
     if (src == NULL) {
         ERR_raise(ERR_LIB_EC, ERR_R_PASSED_NULL_PARAMETER);
-        goto err;
+        return NULL;
     }
 
+    if ((ret = ossl_ec_key_new_method_int(src->libctx, src->propq,
+                                          src->engine)) == NULL)
+        return NULL;
+
     /* copy the parameters */
     if (src->group != NULL
         && (selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) {