X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Ferr%2Ferr.c;h=2b2ecf4bf238657a8bd977015c0db111fb2fe647;hp=b078442109f6c458627ab1dcc23dc40187310b5f;hb=349807608f31b20af01a342d0072bb92e0b036e2;hpb=3e47caff4830d2a117eda15b57a5feab89b846ae diff --git a/crypto/err/err.c b/crypto/err/err.c index b078442109..2b2ecf4bf2 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -1,4 +1,3 @@ -/* crypto/err/err.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -112,15 +111,14 @@ #include #include #include -#include "cryptlib.h" +#include "internal/cryptlib.h" #include #include #include #include #include - -DECLARE_LHASH_OF(ERR_STRING_DATA); -DECLARE_LHASH_OF(ERR_STATE); +#include +#include "err_lcl.h" static void err_load_strings(int lib, ERR_STRING_DATA *str); @@ -157,6 +155,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = { {ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"}, {ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"}, {ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"}, + {ERR_PACK(ERR_LIB_ASYNC, 0, 0), "ASYNC routines"}, {0, NULL}, }; @@ -240,11 +239,6 @@ static LHASH_OF(ERR_STATE) *int_thread_hash = NULL; static int int_thread_hash_references = 0; static int int_err_library_number = ERR_LIB_USER; -/* - * These are the callbacks provided to "lh_new()" when creating the LHASH - * tables internal to the "err_defaults" implementation. - */ - static unsigned long get_error_values(int inc, int top, const char **file, int *line, const char **data, int *flags); @@ -258,16 +252,12 @@ static unsigned long err_string_data_hash(const ERR_STRING_DATA *a) return (ret ^ ret % 19 * 13); } -static IMPLEMENT_LHASH_HASH_FN(err_string_data, ERR_STRING_DATA) - static int err_string_data_cmp(const ERR_STRING_DATA *a, const ERR_STRING_DATA *b) { return (int)(a->error - b->error); } -static IMPLEMENT_LHASH_COMP_FN(err_string_data, ERR_STRING_DATA) - static LHASH_OF(ERR_STRING_DATA) *get_hash(int create, int lockit) { LHASH_OF(ERR_STRING_DATA) *ret = NULL; @@ -275,11 +265,10 @@ static LHASH_OF(ERR_STRING_DATA) *get_hash(int create, int lockit) if (lockit) CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (!int_error_hash && create) { - CRYPTO_push_info("get_hash (err.c)"); - int_error_hash = lh_ERR_STRING_DATA_new(); - CRYPTO_pop_info(); + int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash, + err_string_data_cmp); } - if (int_error_hash) + if (int_error_hash != NULL) ret = int_error_hash; if (lockit) CRYPTO_w_unlock(CRYPTO_LOCK_ERR); @@ -306,15 +295,11 @@ static unsigned long err_state_hash(const ERR_STATE *a) return CRYPTO_THREADID_hash(&a->tid) * 13; } -static IMPLEMENT_LHASH_HASH_FN(err_state, ERR_STATE) - static int err_state_cmp(const ERR_STATE *a, const ERR_STATE *b) { return CRYPTO_THREADID_cmp(&a->tid, &b->tid); } -static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE) - static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit) { LHASH_OF(ERR_STATE) *ret = NULL; @@ -322,11 +307,9 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit) if (lockit) CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (!int_thread_hash && create) { - CRYPTO_push_info("int_thread_get (err.c)"); - int_thread_hash = lh_ERR_STATE_new(); - CRYPTO_pop_info(); + int_thread_hash = lh_ERR_STATE_new(err_state_hash, err_state_cmp); } - if (int_thread_hash) { + if (int_thread_hash != NULL) { int_thread_hash_references++; ret = int_thread_hash; } @@ -402,15 +385,16 @@ static void int_thread_del_item(const ERR_STATE *d) if (int_thread_hash_references == 1 && int_thread_hash && lh_ERR_STATE_num_items(int_thread_hash) == 0) { + int_thread_hash_references = 0; lh_ERR_STATE_free(int_thread_hash); int_thread_hash = NULL; + hash = NULL; } } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); int_thread_release(&hash); - if (p) - ERR_STATE_free(p); + ERR_STATE_free(p); } #ifndef OPENSSL_NO_ERR @@ -456,8 +440,8 @@ static void build_SYS_str_reasons(void) char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]); char *src = strerror(i); if (src != NULL) { - strncpy(*dest, src, sizeof *dest); - (*dest)[sizeof *dest - 1] = '\0'; + strncpy(*dest, src, sizeof(*dest)); + (*dest)[sizeof(*dest) - 1] = '\0'; str->string = *dest; } } @@ -478,8 +462,7 @@ static void build_SYS_str_reasons(void) #define err_clear_data(p,i) \ do { \ - if (((p)->err_data[i] != NULL) && \ - (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ + if ((p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ { \ OPENSSL_free((p)->err_data[i]); \ (p)->err_data[i]=NULL; \ @@ -561,10 +544,8 @@ void ERR_unload_strings(int lib, ERR_STRING_DATA *str) void ERR_free_strings(void) { CRYPTO_w_lock(CRYPTO_LOCK_ERR); - if (int_error_hash) { - lh_ERR_STRING_DATA_free(int_error_hash); - int_error_hash = NULL; - } + lh_ERR_STRING_DATA_free(int_error_hash); + int_error_hash = NULL; CRYPTO_w_unlock(CRYPTO_LOCK_ERR); } @@ -866,7 +847,7 @@ void ERR_remove_thread_state(const CRYPTO_THREADID *id) int_thread_del_item(&tmp); } -#ifndef OPENSSL_NO_DEPRECATED +#if OPENSSL_API_COMPAT < 0x10000000L void ERR_remove_state(unsigned long pid) { ERR_remove_thread_state(NULL); @@ -886,7 +867,7 @@ ERR_STATE *ERR_get_state(void) /* ret == the error state, if NULL, make a new one */ if (ret == NULL) { - ret = (ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE)); + ret = OPENSSL_malloc(sizeof(*ret)); if (ret == NULL) return (&fallback); CRYPTO_THREADID_cpy(&ret->tid, &tid); @@ -906,8 +887,7 @@ ERR_STATE *ERR_get_state(void) * If a race occurred in this function and we came second, tmpp is * the first one that we just replaced. */ - if (tmpp) - ERR_STATE_free(tmpp); + ERR_STATE_free(tmpp); } return ret; } @@ -969,10 +949,10 @@ void ERR_add_error_vdata(int num, va_list args) if (p == NULL) { OPENSSL_free(str); return; - } else - str = p; + } + str = p; } - BUF_strlcat(str, a, (size_t)s + 1); + OPENSSL_strlcat(str, a, (size_t)s + 1); } } ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING);