diff options
author | Richard Levitte <levitte@openssl.org> | 2023-04-20 07:22:53 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2023-05-01 11:31:33 +0100 |
commit | d1b2c9bf0b076c06dd240cab6140c68ec9f2cf5c (patch) | |
tree | f33f652f19a1ca4da2ae22c0b620eb781402bef7 | |
parent | 925058987e4b48ed5c71bbf46742713b50feeb2d (diff) | |
download | openssl-new-d1b2c9bf0b076c06dd240cab6140c68ec9f2cf5c.tar.gz |
param->ctrl translation: Fix fix_ec_paramgen_curve_nid()
This function didn't prepare space to get the param string, which causes
the default_fixup_args() call to fail.
Fixes #20161
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/20780)
(cherry picked from commit ac52fe5f5ae7a1d062f09adab7744e3a3b2ddbcf)
-rw-r--r-- | crypto/evp/ctrl_params_translate.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/crypto/evp/ctrl_params_translate.c b/crypto/evp/ctrl_params_translate.c index ac298cfc7e..d2e543a2cd 100644 --- a/crypto/evp/ctrl_params_translate.c +++ b/crypto/evp/ctrl_params_translate.c @@ -1136,6 +1136,7 @@ static int fix_ec_paramgen_curve_nid(enum state state, const struct translation_st *translation, struct translation_ctx_st *ctx) { + char *p2 = NULL; int ret; if ((ret = default_check(state, translation, ctx)) <= 0) @@ -1148,13 +1149,25 @@ static int fix_ec_paramgen_curve_nid(enum state state, if (state == PRE_CTRL_TO_PARAMS) { ctx->p2 = (char *)OBJ_nid2sn(ctx->p1); ctx->p1 = 0; + } else if (state == PRE_PARAMS_TO_CTRL) { + /* + * We're translating from params to ctrl and setting the curve name. + * The ctrl function needs it to be a NID, but meanwhile, we need + * space to get the curve name from the param. |ctx->name_buf| is + * sufficient for that. + * The double indirection is necessary for default_fixup_args()'s + * call of OSSL_PARAM_get_utf8_string() to be done correctly. + */ + p2 = ctx->name_buf; + ctx->p2 = &p2; + ctx->sz = sizeof(ctx->name_buf); } if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; if (state == PRE_PARAMS_TO_CTRL) { - ctx->p1 = OBJ_sn2nid(ctx->p2); + ctx->p1 = OBJ_sn2nid(p2); ctx->p2 = NULL; } |