summaryrefslogtreecommitdiffstats
path: root/providers
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2020-11-18 11:32:33 +1000
committerShane Lontis <shane.lontis@oracle.com>2020-11-20 11:59:23 +1000
commitf2a7151849a566892912737f7b633c04f64a2b9e (patch)
treed0f3046e6d519d66137111a426c80a60fbd22adf /providers
parentae2e4d1fd11910245b6f7b4db31cccf1ff4bec60 (diff)
Fix crash in genpkey app when -pkeyopt digest:name is used for DH or DSA.
By the time the keygen is called the references to strings inside the gen ctx are floating pointers. A strdup solves this problem. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/13432)
Diffstat (limited to 'providers')
-rw-r--r--providers/implementations/keymgmt/dh_kmgmt.c16
-rw-r--r--providers/implementations/keymgmt/dsa_kmgmt.c16
2 files changed, 24 insertions, 8 deletions
diff --git a/providers/implementations/keymgmt/dh_kmgmt.c b/providers/implementations/keymgmt/dh_kmgmt.c
index 927246167e..dc0f3b2acd 100644
--- a/providers/implementations/keymgmt/dh_kmgmt.c
+++ b/providers/implementations/keymgmt/dh_kmgmt.c
@@ -69,8 +69,8 @@ struct dh_gen_ctx {
int hindex;
int priv_len;
- const char *mdname;
- const char *mdprops;
+ char *mdname;
+ char *mdprops;
OSSL_CALLBACK *cb;
void *cbarg;
int dh_type;
@@ -549,13 +549,19 @@ static int dh_gen_set_params(void *genctx, const OSSL_PARAM params[])
if (p != NULL) {
if (p->data_type != OSSL_PARAM_UTF8_STRING)
return 0;
- gctx->mdname = p->data;
+ OPENSSL_free(gctx->mdname);
+ gctx->mdname = OPENSSL_strdup(p->data);
+ if (gctx->mdname == NULL)
+ return 0;
}
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS);
if (p != NULL) {
if (p->data_type != OSSL_PARAM_UTF8_STRING)
return 0;
- gctx->mdprops = p->data;
+ OPENSSL_free(gctx->mdprops);
+ gctx->mdprops = OPENSSL_strdup(p->data);
+ if (gctx->mdprops == NULL)
+ return 0;
}
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_PRIV_LEN);
if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->priv_len))
@@ -694,6 +700,8 @@ static void dh_gen_cleanup(void *genctx)
if (gctx == NULL)
return;
+ OPENSSL_free(gctx->mdname);
+ OPENSSL_free(gctx->mdprops);
OPENSSL_clear_free(gctx->seed, gctx->seedlen);
OPENSSL_free(gctx);
}
diff --git a/providers/implementations/keymgmt/dsa_kmgmt.c b/providers/implementations/keymgmt/dsa_kmgmt.c
index 6dbd450386..bc4591b1d6 100644
--- a/providers/implementations/keymgmt/dsa_kmgmt.c
+++ b/providers/implementations/keymgmt/dsa_kmgmt.c
@@ -63,8 +63,8 @@ struct dsa_gen_ctx {
int gen_type; /* DSA_PARAMGEN_TYPE_FIPS_186_2 or DSA_PARAMGEN_TYPE_FIPS_186_4 */
int pcounter;
int hindex;
- const char *mdname;
- const char *mdprops;
+ char *mdname;
+ char *mdprops;
OSSL_CALLBACK *cb;
void *cbarg;
};
@@ -459,13 +459,19 @@ static int dsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
if (p != NULL) {
if (p->data_type != OSSL_PARAM_UTF8_STRING)
return 0;
- gctx->mdname = p->data;
+ OPENSSL_free(gctx->mdname);
+ gctx->mdname = OPENSSL_strdup(p->data);
+ if (gctx->mdname == NULL)
+ return 0;
}
p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS);
if (p != NULL) {
if (p->data_type != OSSL_PARAM_UTF8_STRING)
return 0;
- gctx->mdprops = p->data;
+ OPENSSL_free(gctx->mdprops);
+ gctx->mdprops = OPENSSL_strdup(p->data);
+ if (gctx->mdprops == NULL)
+ return 0;
}
return 1;
}
@@ -572,6 +578,8 @@ static void dsa_gen_cleanup(void *genctx)
if (gctx == NULL)
return;
+ OPENSSL_free(gctx->mdname);
+ OPENSSL_free(gctx->mdprops);
OPENSSL_clear_free(gctx->seed, gctx->seedlen);
OPENSSL_free(gctx);
}