diff options
author | Rich Salz <rsalz@akamai.com> | 2016-02-10 09:55:48 -0500 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-02-11 08:43:46 -0500 |
commit | 7253fd550c768979ecd3df8f4dbbedd6e9dd76b0 (patch) | |
tree | 6adaf42e67e464dbb90a55514279a35637476f08 /crypto | |
parent | 5caef3b5028599958bfddbdb86ea4f47df9f315b (diff) |
Hide OPENSSL_INIT_SETTINGS.
Make OPENSSL_INIT_SETTINGS an opaque structure.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/conf/conf_lib.c | 28 | ||||
-rw-r--r-- | crypto/conf/conf_sap.c | 10 | ||||
-rw-r--r-- | crypto/init.c | 25 |
3 files changed, 34 insertions, 29 deletions
diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c index 849b670e10..29357b26ad 100644 --- a/crypto/conf/conf_lib.c +++ b/crypto/conf/conf_lib.c @@ -57,6 +57,8 @@ */ #include <stdio.h> +#include <string.h> +#include <internal/conf.h> #include <openssl/crypto.h> #include <openssl/err.h> #include <openssl/conf.h> @@ -370,3 +372,29 @@ int NCONF_dump_bio(const CONF *conf, BIO *out) return conf->meth->dump(conf, out); } + +/* + * These routines call the C malloc/free, to avoid intermixing with + * OpenSSL function pointers before the library is initialized. + */ +OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void) +{ + OPENSSL_INIT_SETTINGS *ret = malloc(sizeof(*ret)); + + memset(ret, 0, sizeof(*ret)); + return ret; +} + + +void OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings, + const char *config_file) +{ + free(settings->config_name); + settings->config_name = config_file == NULL ? NULL : strdup(config_file); +} + +void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings) +{ + free(settings->config_name); + free(settings); +} diff --git a/crypto/conf/conf_sap.c b/crypto/conf/conf_sap.c index 3b42993143..45c08e677c 100644 --- a/crypto/conf/conf_sap.c +++ b/crypto/conf/conf_sap.c @@ -77,13 +77,11 @@ static int openssl_configured = 0; void OPENSSL_config(const char *config_name) { - OPENSSL_INIT_SETTINGS settings[2]; + OPENSSL_INIT_SETTINGS settings; - settings[0].name = OPENSSL_INIT_SET_CONF_FILENAME; - settings[0].value.type_string = config_name; - settings[1].name = OPENSSL_INIT_SET_END; - settings[1].value.type_int = 0; - OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, settings); + memset(&settings, 0, sizeof(settings)); + settings.config_name = strdup(config_name); + OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings); } void openssl_config_internal(const char *config_name) diff --git a/crypto/init.c b/crypto/init.c index e6dd084f55..e58b119913 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -253,6 +253,7 @@ static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc) #endif +typedef struct ossl_init_stop_st OPENSSL_INIT_STOP; struct ossl_init_stop_st { void (*handler)(void); OPENSSL_INIT_STOP *next; @@ -606,21 +607,6 @@ void OPENSSL_cleanup(void) base_inited = 0; } -static const OPENSSL_INIT_SETTINGS *ossl_init_get_setting( - const OPENSSL_INIT_SETTINGS *settings, int name) -{ - if (settings == NULL) - return NULL; - - while (settings->name != OPENSSL_INIT_SET_END) { - if (settings->name == name) - return settings; - settings++; - } - - return NULL; -} - /* * If this function is called with a non NULL settings value then it must be * called prior to any threads making calls to any OpenSSL functions, @@ -670,14 +656,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) if (opts & OPENSSL_INIT_LOAD_CONFIG) { CRYPTO_w_lock(CRYPTO_LOCK_INIT); - if (settings != NULL) { - const OPENSSL_INIT_SETTINGS *curr; - curr = ossl_init_get_setting(settings, - OPENSSL_INIT_SET_CONF_FILENAME); - config_filename = (curr == NULL) ? NULL : curr->value.type_string; - } else { - config_filename = NULL; - } + config_filename = (settings == NULL) ? NULL : settings->config_name; ossl_init_once_run(&config, ossl_init_config); CRYPTO_w_unlock(CRYPTO_LOCK_INIT); } |