summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-10-17 00:32:20 +0200
committerRichard Levitte <levitte@openssl.org>2019-10-17 18:07:45 +0200
commit651101e18d66b2ae89851ce8906299e9d2a871e0 (patch)
treeacee0bbb71d49390a74461b58204dd899ef6b08e /crypto
parent5a02d13d3e274748c695bfe19238f885489e021e (diff)
evp_keymgmt_export_to_provider(): adjust OSSL_PARAM array for transfer
It may be that the OSSL_PARAM array we used for getting parameter values for a key had a few too many entries. These are detected by their return_size == 0. Before making second export call, we prune away these items so we only ask for parameters that exist. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/10190)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/keymgmt_lib.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/crypto/evp/keymgmt_lib.c b/crypto/evp/keymgmt_lib.c
index 87629157e2..a14decd280 100644
--- a/crypto/evp/keymgmt_lib.c
+++ b/crypto/evp/keymgmt_lib.c
@@ -37,6 +37,28 @@ static OSSL_PARAM *paramdefs_to_params(const OSSL_PARAM *paramdefs)
return params;
}
+static OSSL_PARAM *reduce_params(OSSL_PARAM *params)
+{
+ OSSL_PARAM *curr, *next;
+ size_t cnt;
+
+ for (cnt = 0, curr = next = params; next->key != NULL; next++) {
+ if (next->return_size == 0)
+ continue;
+ if (curr != next)
+ *curr = *next;
+ curr++;
+ cnt++;
+ }
+ *curr = *next; /* Terminating record */
+ cnt++;
+
+ curr = OPENSSL_realloc(params, cnt * sizeof(*params));
+ if (curr == NULL)
+ return params;
+ return curr;
+}
+
typedef union align_block_un {
OSSL_UNION_ALIGN;
} ALIGN_BLOCK;
@@ -157,10 +179,11 @@ void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt,
exportfn(pk->pkeys[j].provdata, params);
/*
- * Allocate space and assign 'data' to point into the
- * data block.
- * If something goes wrong, go to the next cached key.
+ * Reduce the params by removing any entry that got return
+ * size zero, then allocate space and assign 'data' to point
+ * into the data block
*/
+ params = reduce_params(params);
if ((data = allocate_params_space(params)) == NULL)
goto cont;