diff options
author | Matt Caswell <matt@openssl.org> | 2022-06-09 12:02:37 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2022-06-15 11:53:43 +0100 |
commit | 76a597c512a055556a5033c69ce02d6330e8a2af (patch) | |
tree | c47eb639a81154926459105f10e97a5ecba89a21 /providers/implementations | |
parent | 6cd7fe2a7f692ffbd4f9acfc67caa80b315f881d (diff) |
Fix the export routines to not return success if param alloc failed
We fix the dsa, dh, ec and rsa export routines so that they are
consistent with each other and do not report success if the allocation
of parameters failed.
This is essentially the same fix as applied in #18483 but applied to all
relevant key types.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18507)
(cherry picked from commit 46c1c2d7fa9153da4eb5e1aefd7b0139dc507c00)
Diffstat (limited to 'providers/implementations')
-rw-r--r-- | providers/implementations/keymgmt/dh_kmgmt.c | 4 | ||||
-rw-r--r-- | providers/implementations/keymgmt/dsa_kmgmt.c | 5 | ||||
-rw-r--r-- | providers/implementations/keymgmt/ec_kmgmt.c | 10 | ||||
-rw-r--r-- | providers/implementations/keymgmt/rsa_kmgmt.c | 5 |
4 files changed, 14 insertions, 10 deletions
diff --git a/providers/implementations/keymgmt/dh_kmgmt.c b/providers/implementations/keymgmt/dh_kmgmt.c index 88fddf51de..58a5fd009f 100644 --- a/providers/implementations/keymgmt/dh_kmgmt.c +++ b/providers/implementations/keymgmt/dh_kmgmt.c @@ -236,11 +236,11 @@ static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, ok = ok && ossl_dh_key_todata(dh, tmpl, NULL, include_private); } - if (!ok - || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { + if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { ok = 0; goto err; } + ok = param_cb(params, cbarg); OSSL_PARAM_free(params); err: diff --git a/providers/implementations/keymgmt/dsa_kmgmt.c b/providers/implementations/keymgmt/dsa_kmgmt.c index 2ab69f5f32..100e917167 100644 --- a/providers/implementations/keymgmt/dsa_kmgmt.c +++ b/providers/implementations/keymgmt/dsa_kmgmt.c @@ -235,9 +235,10 @@ static int dsa_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, ok = ok && dsa_key_todata(dsa, tmpl, NULL, include_private); } - if (!ok - || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) + if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { + ok = 0; goto err; + } ok = param_cb(params, cbarg); OSSL_PARAM_free(params); diff --git a/providers/implementations/keymgmt/ec_kmgmt.c b/providers/implementations/keymgmt/ec_kmgmt.c index bfaae4f234..0d244054e6 100644 --- a/providers/implementations/keymgmt/ec_kmgmt.c +++ b/providers/implementations/keymgmt/ec_kmgmt.c @@ -496,12 +496,14 @@ int ec_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0) ok = ok && otherparams_to_params(ec, tmpl, NULL); - if (ok && (params = OSSL_PARAM_BLD_to_param(tmpl)) != NULL) - ok = param_cb(params, cbarg); - else + if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { ok = 0; -end: + goto end; + } + + ok = param_cb(params, cbarg); OSSL_PARAM_free(params); +end: OSSL_PARAM_BLD_free(tmpl); OPENSSL_free(pub_key); OPENSSL_free(genbuf); diff --git a/providers/implementations/keymgmt/rsa_kmgmt.c b/providers/implementations/keymgmt/rsa_kmgmt.c index 1528e43adb..b76835ccc4 100644 --- a/providers/implementations/keymgmt/rsa_kmgmt.c +++ b/providers/implementations/keymgmt/rsa_kmgmt.c @@ -229,9 +229,10 @@ static int rsa_export(void *keydata, int selection, ok = ok && ossl_rsa_todata(rsa, tmpl, NULL, include_private); } - if (!ok - || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) + if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { + ok = 0; goto err; + } ok = param_callback(params, cbarg); OSSL_PARAM_free(params); |