aboutsummaryrefslogtreecommitdiff
path: root/crypto/err/err.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/err/err.c')
-rw-r--r--crypto/err/err.c83
1 files changed, 15 insertions, 68 deletions
diff --git a/crypto/err/err.c b/crypto/err/err.c
index ec55642308c4..b95182d7029a 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -23,7 +23,7 @@
#include "internal/thread_once.h"
#include "crypto/ctype.h"
#include "internal/constant_time.h"
-#include "e_os.h"
+#include "internal/e_os.h"
#include "err_local.h"
/* Forward declaration in case it's not published because of configuration */
@@ -33,7 +33,6 @@ ERR_STATE *ERR_get_state(void);
static int err_load_strings(const ERR_STRING_DATA *str);
#endif
-static void ERR_STATE_free(ERR_STATE *s);
#ifndef OPENSSL_NO_ERR
static ERR_STRING_DATA ERR_str_libraries[] = {
{ERR_PACK(ERR_LIB_NONE, 0, 0), "unknown library"},
@@ -199,16 +198,16 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
}
#endif
-static void ERR_STATE_free(ERR_STATE *s)
+void OSSL_ERR_STATE_free(ERR_STATE *state)
{
int i;
- if (s == NULL)
+ if (state == NULL)
return;
for (i = 0; i < ERR_NUM_ERRORS; i++) {
- err_clear(s, i, 1);
+ err_clear(state, i, 1);
}
- OPENSSL_free(s);
+ CRYPTO_free(state, OPENSSL_FILE, OPENSSL_LINE);
}
DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
@@ -552,7 +551,8 @@ void ossl_err_string_int(unsigned long e, const char *func,
}
#endif
if (rs == NULL) {
- BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
+ BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)",
+ r & ~(ERR_RFLAGS_MASK << ERR_RFLAGS_OFFSET));
rs = rsbuf;
}
@@ -648,7 +648,7 @@ static void err_delete_thread_state(void *unused)
return;
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
- ERR_STATE_free(state);
+ OSSL_ERR_STATE_free(state);
}
#ifndef OPENSSL_NO_DEPRECATED_1_1_0
@@ -688,14 +688,15 @@ ERR_STATE *ossl_err_get_state_int(void)
if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))
return NULL;
- if ((state = OPENSSL_zalloc(sizeof(*state))) == NULL) {
+ state = OSSL_ERR_STATE_new();
+ if (state == NULL) {
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
return NULL;
}
if (!ossl_init_thread_start(NULL, NULL, err_delete_thread_state)
|| !CRYPTO_THREAD_set_local(&err_thread_local, state)) {
- ERR_STATE_free(state);
+ OSSL_ERR_STATE_free(state);
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
return NULL;
}
@@ -830,10 +831,11 @@ void ERR_add_error_vdata(int num, va_list args)
i = es->top;
/*
- * If err_data is allocated already, re-use the space.
+ * If err_data is allocated already, reuse the space.
* Otherwise, allocate a small new buffer.
*/
- if ((es->err_data_flags[i] & flags) == flags) {
+ if ((es->err_data_flags[i] & flags) == flags
+ && ossl_assert(es->err_data[i] != NULL)) {
str = es->err_data[i];
size = es->err_data_size[i];
@@ -875,61 +877,6 @@ void ERR_add_error_vdata(int num, va_list args)
OPENSSL_free(str);
}
-int ERR_set_mark(void)
-{
- ERR_STATE *es;
-
- es = ossl_err_get_state_int();
- if (es == NULL)
- return 0;
-
- if (es->bottom == es->top)
- return 0;
- es->err_marks[es->top]++;
- return 1;
-}
-
-int ERR_pop_to_mark(void)
-{
- ERR_STATE *es;
-
- es = ossl_err_get_state_int();
- if (es == NULL)
- return 0;
-
- while (es->bottom != es->top
- && es->err_marks[es->top] == 0) {
- err_clear(es, es->top, 0);
- es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
- }
-
- if (es->bottom == es->top)
- return 0;
- es->err_marks[es->top]--;
- return 1;
-}
-
-int ERR_clear_last_mark(void)
-{
- ERR_STATE *es;
- int top;
-
- es = ossl_err_get_state_int();
- if (es == NULL)
- return 0;
-
- top = es->top;
- while (es->bottom != top
- && es->err_marks[top] == 0) {
- top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
- }
-
- if (es->bottom == top)
- return 0;
- es->err_marks[top]--;
- return 1;
-}
-
void err_clear_last_constant_time(int clear)
{
ERR_STATE *es;