/src/openssl/crypto/err/err_local.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include <string.h> |
11 | | #include <openssl/err.h> |
12 | | #include <openssl/e_os2.h> |
13 | | #include "internal/err.h" |
14 | | |
15 | | #define ERR_FLAG_MARK 0x01 |
16 | 4 | #define ERR_FLAG_CLEAR 0x02 |
17 | | |
18 | | struct err_state_st { |
19 | | int err_flags[ERR_NUM_ERRORS]; |
20 | | int err_marks[ERR_NUM_ERRORS]; |
21 | | unsigned long err_buffer[ERR_NUM_ERRORS]; |
22 | | char *err_data[ERR_NUM_ERRORS]; |
23 | | size_t err_data_size[ERR_NUM_ERRORS]; |
24 | | int err_data_flags[ERR_NUM_ERRORS]; |
25 | | char *err_file[ERR_NUM_ERRORS]; |
26 | | int err_line[ERR_NUM_ERRORS]; |
27 | | char *err_func[ERR_NUM_ERRORS]; |
28 | | int top, bottom; |
29 | | }; |
30 | | |
31 | | static ossl_inline void err_get_slot(ERR_STATE *es) |
32 | 1.04k | { |
33 | 1.04k | es->top = (es->top + 1) % ERR_NUM_ERRORS; |
34 | 1.04k | if (es->top == es->bottom) |
35 | 1.00k | es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS; |
36 | 1.04k | } Unexecuted instantiation: err.c:err_get_slot Unexecuted instantiation: err_save.c:err_get_slot err_blocks.c:err_get_slot Line | Count | Source | 32 | 1.04k | { | 33 | 1.04k | es->top = (es->top + 1) % ERR_NUM_ERRORS; | 34 | 1.04k | if (es->top == es->bottom) | 35 | 1.00k | es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS; | 36 | 1.04k | } |
Unexecuted instantiation: err_mark.c:err_get_slot Unexecuted instantiation: err_prn.c:err_get_slot |
37 | | |
38 | | static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall) |
39 | 2.08k | { |
40 | 2.08k | if (es->err_data_flags[i] & ERR_TXT_MALLOCED) { |
41 | 1.00k | if (deall) { |
42 | 0 | OPENSSL_free(es->err_data[i]); |
43 | 0 | es->err_data[i] = NULL; |
44 | 0 | es->err_data_size[i] = 0; |
45 | 0 | es->err_data_flags[i] = 0; |
46 | 1.00k | } else if (es->err_data[i] != NULL) { |
47 | 1.00k | es->err_data[i][0] = '\0'; |
48 | 1.00k | es->err_data_flags[i] = ERR_TXT_MALLOCED; |
49 | 1.00k | } |
50 | 1.07k | } else { |
51 | 1.07k | es->err_data[i] = NULL; |
52 | 1.07k | es->err_data_size[i] = 0; |
53 | 1.07k | es->err_data_flags[i] = 0; |
54 | 1.07k | } |
55 | 2.08k | } Unexecuted instantiation: err.c:err_clear_data Unexecuted instantiation: err_save.c:err_clear_data err_blocks.c:err_clear_data Line | Count | Source | 39 | 2.08k | { | 40 | 2.08k | if (es->err_data_flags[i] & ERR_TXT_MALLOCED) { | 41 | 1.00k | if (deall) { | 42 | 0 | OPENSSL_free(es->err_data[i]); | 43 | 0 | es->err_data[i] = NULL; | 44 | 0 | es->err_data_size[i] = 0; | 45 | 0 | es->err_data_flags[i] = 0; | 46 | 1.00k | } else if (es->err_data[i] != NULL) { | 47 | 1.00k | es->err_data[i][0] = '\0'; | 48 | 1.00k | es->err_data_flags[i] = ERR_TXT_MALLOCED; | 49 | 1.00k | } | 50 | 1.07k | } else { | 51 | | es->err_data[i] = NULL; | 52 | 1.07k | es->err_data_size[i] = 0; | 53 | 1.07k | es->err_data_flags[i] = 0; | 54 | 1.07k | } | 55 | 2.08k | } |
err_mark.c:err_clear_data Line | Count | Source | 39 | 3 | { | 40 | 3 | if (es->err_data_flags[i] & ERR_TXT_MALLOCED) { | 41 | 1 | if (deall) { | 42 | 0 | OPENSSL_free(es->err_data[i]); | 43 | 0 | es->err_data[i] = NULL; | 44 | 0 | es->err_data_size[i] = 0; | 45 | 0 | es->err_data_flags[i] = 0; | 46 | 1 | } else if (es->err_data[i] != NULL) { | 47 | 1 | es->err_data[i][0] = '\0'; | 48 | 1 | es->err_data_flags[i] = ERR_TXT_MALLOCED; | 49 | 1 | } | 50 | 2 | } else { | 51 | | es->err_data[i] = NULL; | 52 | 2 | es->err_data_size[i] = 0; | 53 | 2 | es->err_data_flags[i] = 0; | 54 | 2 | } | 55 | 3 | } |
Unexecuted instantiation: err_prn.c:err_clear_data |
56 | | |
57 | | static ossl_inline void err_set_error(ERR_STATE *es, size_t i, |
58 | | int lib, int reason) |
59 | 1.04k | { |
60 | 1.04k | es->err_buffer[i] = lib == ERR_LIB_SYS |
61 | 1.04k | ? (unsigned int)(ERR_SYSTEM_FLAG | reason) |
62 | 1.04k | : ERR_PACK(lib, 0, reason); |
63 | 1.04k | } Unexecuted instantiation: err.c:err_set_error Unexecuted instantiation: err_save.c:err_set_error err_blocks.c:err_set_error Line | Count | Source | 59 | 1.04k | { | 60 | 1.04k | es->err_buffer[i] = lib == ERR_LIB_SYS | 61 | 1.04k | ? (unsigned int)(ERR_SYSTEM_FLAG | reason) | 62 | 1.04k | : ERR_PACK(lib, 0, reason); | 63 | 1.04k | } |
Unexecuted instantiation: err_mark.c:err_set_error Unexecuted instantiation: err_prn.c:err_set_error |
64 | | |
65 | | static ossl_inline void err_set_debug(ERR_STATE *es, size_t i, |
66 | | const char *file, int line, |
67 | | const char *fn) |
68 | 1.04k | { |
69 | | /* |
70 | | * We dup the file and fn strings because they may be provider owned. If the |
71 | | * provider gets unloaded, they may not be valid anymore. |
72 | | */ |
73 | 1.04k | OPENSSL_free(es->err_file[i]); |
74 | 1.04k | if (file == NULL || file[0] == '\0') |
75 | 0 | es->err_file[i] = NULL; |
76 | 1.04k | else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1, |
77 | 1.04k | NULL, 0)) |
78 | 1.04k | != NULL) |
79 | | /* We cannot use OPENSSL_strdup due to possible recursion */ |
80 | 1.04k | strcpy(es->err_file[i], file); |
81 | | |
82 | 1.04k | es->err_line[i] = line; |
83 | 1.04k | OPENSSL_free(es->err_func[i]); |
84 | 1.04k | if (fn == NULL || fn[0] == '\0') |
85 | 0 | es->err_func[i] = NULL; |
86 | 1.04k | else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1, |
87 | 1.04k | NULL, 0)) |
88 | 1.04k | != NULL) |
89 | 1.04k | strcpy(es->err_func[i], fn); |
90 | 1.04k | } Unexecuted instantiation: err.c:err_set_debug Unexecuted instantiation: err_save.c:err_set_debug err_blocks.c:err_set_debug Line | Count | Source | 68 | 1.04k | { | 69 | | /* | 70 | | * We dup the file and fn strings because they may be provider owned. If the | 71 | | * provider gets unloaded, they may not be valid anymore. | 72 | | */ | 73 | 1.04k | OPENSSL_free(es->err_file[i]); | 74 | 1.04k | if (file == NULL || file[0] == '\0') | 75 | 0 | es->err_file[i] = NULL; | 76 | 1.04k | else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1, | 77 | 1.04k | NULL, 0)) | 78 | 1.04k | != NULL) | 79 | | /* We cannot use OPENSSL_strdup due to possible recursion */ | 80 | 1.04k | strcpy(es->err_file[i], file); | 81 | | | 82 | 1.04k | es->err_line[i] = line; | 83 | 1.04k | OPENSSL_free(es->err_func[i]); | 84 | 1.04k | if (fn == NULL || fn[0] == '\0') | 85 | 0 | es->err_func[i] = NULL; | 86 | 1.04k | else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1, | 87 | 1.04k | NULL, 0)) | 88 | 1.04k | != NULL) | 89 | 1.04k | strcpy(es->err_func[i], fn); | 90 | 1.04k | } |
Unexecuted instantiation: err_mark.c:err_set_debug Unexecuted instantiation: err_prn.c:err_set_debug |
91 | | |
92 | | static ossl_inline void err_set_data(ERR_STATE *es, size_t i, |
93 | | void *data, size_t datasz, int flags) |
94 | 1.03k | { |
95 | 1.03k | if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0) |
96 | 0 | OPENSSL_free(es->err_data[i]); |
97 | 1.03k | es->err_data[i] = data; |
98 | 1.03k | es->err_data_size[i] = datasz; |
99 | 1.03k | es->err_data_flags[i] = flags; |
100 | 1.03k | } Unexecuted instantiation: err.c:err_set_data Unexecuted instantiation: err_save.c:err_set_data err_blocks.c:err_set_data Line | Count | Source | 94 | 1.03k | { | 95 | 1.03k | if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0) | 96 | 0 | OPENSSL_free(es->err_data[i]); | 97 | 1.03k | es->err_data[i] = data; | 98 | 1.03k | es->err_data_size[i] = datasz; | 99 | 1.03k | es->err_data_flags[i] = flags; | 100 | 1.03k | } |
Unexecuted instantiation: err_mark.c:err_set_data Unexecuted instantiation: err_prn.c:err_set_data |
101 | | |
102 | | static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall) |
103 | 1.04k | { |
104 | 1.04k | err_clear_data(es, i, (deall)); |
105 | 1.04k | es->err_marks[i] = 0; |
106 | 1.04k | es->err_flags[i] = 0; |
107 | 1.04k | es->err_buffer[i] = 0; |
108 | 1.04k | es->err_line[i] = -1; |
109 | 1.04k | OPENSSL_free(es->err_file[i]); |
110 | 1.04k | es->err_file[i] = NULL; |
111 | 1.04k | OPENSSL_free(es->err_func[i]); |
112 | | es->err_func[i] = NULL; |
113 | 1.04k | } Unexecuted instantiation: err.c:err_clear Unexecuted instantiation: err_save.c:err_clear Line | Count | Source | 103 | 1.04k | { | 104 | 1.04k | err_clear_data(es, i, (deall)); | 105 | 1.04k | es->err_marks[i] = 0; | 106 | 1.04k | es->err_flags[i] = 0; | 107 | 1.04k | es->err_buffer[i] = 0; | 108 | 1.04k | es->err_line[i] = -1; | 109 | 1.04k | OPENSSL_free(es->err_file[i]); | 110 | 1.04k | es->err_file[i] = NULL; | 111 | 1.04k | OPENSSL_free(es->err_func[i]); | 112 | | es->err_func[i] = NULL; | 113 | 1.04k | } |
Line | Count | Source | 103 | 3 | { | 104 | 3 | err_clear_data(es, i, (deall)); | 105 | 3 | es->err_marks[i] = 0; | 106 | 3 | es->err_flags[i] = 0; | 107 | 3 | es->err_buffer[i] = 0; | 108 | 3 | es->err_line[i] = -1; | 109 | 3 | OPENSSL_free(es->err_file[i]); | 110 | 3 | es->err_file[i] = NULL; | 111 | 3 | OPENSSL_free(es->err_func[i]); | 112 | | es->err_func[i] = NULL; | 113 | 3 | } |
Unexecuted instantiation: err_prn.c:err_clear |
114 | | |
115 | | ERR_STATE *ossl_err_get_state_int(void); |
116 | | void ossl_err_string_int(unsigned long e, const char *func, |
117 | | char *buf, size_t len); |