From e3c722f274f8c08f6256d4142ea1693be3d1565d Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Fri, 6 Jan 2023 12:04:45 +0200 Subject: [PATCH] Use empty entry to indicate end of aliases --- ext/openssl/ossl_pkey.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index ba8c507d3..7539e05a2 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -437,19 +437,20 @@ static const struct pkey_from_parameters_alias rsa_aliases[] = { { "q", OSSL_PKEY_PARAM_RSA_FACTOR2 }, { "dmp1", OSSL_PKEY_PARAM_RSA_EXPONENT1 }, { "dmq1", OSSL_PKEY_PARAM_RSA_EXPONENT2 }, - { "iqmp", OSSL_PKEY_PARAM_RSA_COEFFICIENT1 } + { "iqmp", OSSL_PKEY_PARAM_RSA_COEFFICIENT1 }, + { "", "" } }; static const struct pkey_from_parameters_alias fcc_aliases[] = { { "pub_key", OSSL_PKEY_PARAM_PUB_KEY }, - { "priv_key", OSSL_PKEY_PARAM_PRIV_KEY } + { "priv_key", OSSL_PKEY_PARAM_PRIV_KEY }, + { "", "" } }; struct pkey_from_parameters_arg { OSSL_PARAM_BLD *param_bld; const OSSL_PARAM *settable_params; const struct pkey_from_parameters_alias *aliases; - size_t nAliases; }; static int @@ -463,7 +464,7 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) { const char *key_ptr = StringValueCStr(key); const struct pkey_from_parameters_arg *params = (const struct pkey_from_parameters_arg *) arg; - for(size_t i = 0; i < params->nAliases; i++) { + for(int i = 0; strlen(params->aliases[i].alias) > 0; i++) { if(strcmp(params->aliases[i].alias, key_ptr) == 0) { key_ptr = params->aliases[i].param_name; break; @@ -517,7 +518,7 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) { cur += snprintf(cur, end-cur, fmt, settable_params->key); } - for(size_t i = 0; i < params->nAliases; i++) { + for(int i = 0; strlen(params->aliases[i].alias) > 0; i++) { const char *fmt = cur == message_buffer ? "%s" : ", %s"; if (cur > end) break; @@ -556,13 +557,10 @@ pkey_from_parameters(int argc, VALUE *argv, VALUE self) ossl_raise(ePKeyError, "EVP_PKEY_fromdata_settable"); } - if (strcmp("RSA", algorithm) == 0) { + if (strcmp("RSA", algorithm) == 0) from_params_args.aliases = rsa_aliases; - from_params_args.nAliases = sizeof(rsa_aliases)/sizeof((rsa_aliases)[0]); - } else { + else from_params_args.aliases = fcc_aliases; - from_params_args.nAliases = sizeof(fcc_aliases)/sizeof((fcc_aliases)[0]); - } rb_hash_foreach(options, &add_parameter_to_builder, (VALUE) &from_params_args);