]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Always create a key when importing
authorMatt Caswell <matt@openssl.org>
Thu, 21 May 2020 10:33:53 +0000 (11:33 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 5 Jun 2020 10:04:11 +0000 (11:04 +0100)
Even if there is no data to import we should still create an empty key.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11898)

crypto/evp/keymgmt_lib.c

index a712233043e9ed3b31e8d4a8dde4bfea078a101c..68ed74b23a2e3797a9d9df35128b739875a612fa 100644 (file)
@@ -39,6 +39,13 @@ static int try_import(const OSSL_PARAM params[], void *arg)
 {
     struct import_data_st *data = arg;
 
+    /* Just in time creation of keydata */
+    if (data->keydata == NULL
+        && (data->keydata = evp_keymgmt_newdata(data->keymgmt)) == NULL) {
+        ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
+        return 0;
+    }
+
     /*
      * It's fine if there was no data to transfer, we just end up with an
      * empty destination key.
@@ -46,13 +53,6 @@ static int try_import(const OSSL_PARAM params[], void *arg)
     if (params[0].key == NULL)
         return 1;
 
-    /* Just in time creation of keydata, if needed */
-    if (data->keydata == NULL
-        && (data->keydata = evp_keymgmt_newdata(data->keymgmt)) == NULL) {
-        ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
-        return 0;
-    }
-
     return evp_keymgmt_import(data->keymgmt, data->keydata, data->selection,
                               params);
 }