Import OpenSSL 1.1.0h
This commit is contained in:
@@ -122,6 +122,7 @@ static ERR_STRING_DATA ERR_str_reasons[] = {
|
||||
#endif
|
||||
|
||||
static CRYPTO_ONCE err_init = CRYPTO_ONCE_STATIC_INIT;
|
||||
static int set_err_thread_local;
|
||||
static CRYPTO_THREAD_LOCAL err_thread_local;
|
||||
|
||||
static CRYPTO_ONCE err_string_init = CRYPTO_ONCE_STATIC_INIT;
|
||||
@@ -260,7 +261,8 @@ DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
|
||||
|
||||
void err_cleanup(void)
|
||||
{
|
||||
CRYPTO_THREAD_cleanup_local(&err_thread_local);
|
||||
if (set_err_thread_local != 0)
|
||||
CRYPTO_THREAD_cleanup_local(&err_thread_local);
|
||||
CRYPTO_THREAD_lock_free(err_string_lock);
|
||||
err_string_lock = NULL;
|
||||
}
|
||||
@@ -359,6 +361,8 @@ void ERR_put_error(int lib, int func, int reason, const char *file, int line)
|
||||
}
|
||||
#endif
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return;
|
||||
|
||||
es->top = (es->top + 1) % ERR_NUM_ERRORS;
|
||||
if (es->top == es->bottom)
|
||||
@@ -376,6 +380,8 @@ void ERR_clear_error(void)
|
||||
ERR_STATE *es;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return;
|
||||
|
||||
for (i = 0; i < ERR_NUM_ERRORS; i++) {
|
||||
err_clear(es, i);
|
||||
@@ -440,6 +446,8 @@ static unsigned long get_error_values(int inc, int top, const char **file,
|
||||
unsigned long ret;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return 0;
|
||||
|
||||
if (inc && top) {
|
||||
if (file)
|
||||
@@ -617,7 +625,7 @@ const char *ERR_reason_error_string(unsigned long e)
|
||||
|
||||
void err_delete_thread_state(void)
|
||||
{
|
||||
ERR_STATE *state = ERR_get_state();
|
||||
ERR_STATE *state = CRYPTO_THREAD_get_local(&err_thread_local);
|
||||
if (state == NULL)
|
||||
return;
|
||||
|
||||
@@ -639,6 +647,7 @@ void ERR_remove_state(unsigned long pid)
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC(err_do_init)
|
||||
{
|
||||
set_err_thread_local = 1;
|
||||
return CRYPTO_THREAD_init_local(&err_thread_local, NULL);
|
||||
}
|
||||
|
||||
@@ -649,6 +658,14 @@ ERR_STATE *ERR_get_state(void)
|
||||
if (!RUN_ONCE(&err_init, err_do_init))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* If base OPENSSL_init_crypto() hasn't been called yet, be sure to call
|
||||
* it now to avoid state to be doubly allocated and thereby leak memory.
|
||||
* Needed on any platform that doesn't define OPENSSL_USE_NODELETE.
|
||||
*/
|
||||
if (!OPENSSL_init_crypto(0, NULL))
|
||||
return NULL;
|
||||
|
||||
state = CRYPTO_THREAD_get_local(&err_thread_local);
|
||||
|
||||
if (state == NULL) {
|
||||
@@ -656,14 +673,14 @@ ERR_STATE *ERR_get_state(void)
|
||||
if (state == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {
|
||||
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)
|
||||
|| !CRYPTO_THREAD_set_local(&err_thread_local, state)) {
|
||||
ERR_STATE_free(state);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ignore failures from these */
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
|
||||
ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);
|
||||
}
|
||||
|
||||
return state;
|
||||
@@ -689,10 +706,10 @@ void ERR_set_error_data(char *data, int flags)
|
||||
int i;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return;
|
||||
|
||||
i = es->top;
|
||||
if (i == 0)
|
||||
i = ERR_NUM_ERRORS - 1;
|
||||
|
||||
err_clear_data(es, i);
|
||||
es->err_data[i] = data;
|
||||
@@ -744,6 +761,8 @@ int ERR_set_mark(void)
|
||||
ERR_STATE *es;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return 0;
|
||||
|
||||
if (es->bottom == es->top)
|
||||
return 0;
|
||||
@@ -756,6 +775,8 @@ int ERR_pop_to_mark(void)
|
||||
ERR_STATE *es;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return 0;
|
||||
|
||||
while (es->bottom != es->top
|
||||
&& (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user