]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/err/err_local.h
Update copyright year
[thirdparty/openssl.git] / crypto / err / err_local.h
1 /*
2 * Copyright 1995-2021 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 <openssl/err.h>
11 #include <openssl/e_os2.h>
12
13 static ossl_inline void err_get_slot(ERR_STATE *es)
14 {
15 es->top = (es->top + 1) % ERR_NUM_ERRORS;
16 if (es->top == es->bottom)
17 es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
18 }
19
20 static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall)
21 {
22 if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
23 if (deall) {
24 OPENSSL_free(es->err_data[i]);
25 es->err_data[i] = NULL;
26 es->err_data_size[i] = 0;
27 es->err_data_flags[i] = 0;
28 } else if (es->err_data[i] != NULL) {
29 es->err_data[i][0] = '\0';
30 }
31 } else {
32 es->err_data[i] = NULL;
33 es->err_data_size[i] = 0;
34 es->err_data_flags[i] = 0;
35 }
36 }
37
38 static ossl_inline void err_set_error(ERR_STATE *es, size_t i,
39 int lib, int reason)
40 {
41 es->err_buffer[i] =
42 lib == ERR_LIB_SYS
43 ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
44 : ERR_PACK(lib, 0, reason);
45 }
46
47 static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
48 const char *file, int line,
49 const char *fn)
50 {
51 /*
52 * We dup the file and fn strings because they may be provider owned. If the
53 * provider gets unloaded, they may not be valid anymore.
54 */
55 OPENSSL_free(es->err_file[i]);
56 if (file == NULL || file[0] == '\0')
57 es->err_file[i] = NULL;
58 else
59 es->err_file[i] = OPENSSL_strdup(file);
60 es->err_line[i] = line;
61 OPENSSL_free(es->err_func[i]);
62 if (fn == NULL || fn[0] == '\0')
63 es->err_func[i] = NULL;
64 else
65 es->err_func[i] = OPENSSL_strdup(fn);
66 }
67
68 static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
69 void *data, size_t datasz, int flags)
70 {
71 es->err_data[i] = data;
72 es->err_data_size[i] = datasz;
73 es->err_data_flags[i] = flags;
74 }
75
76 static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
77 {
78 err_clear_data(es, i, (deall));
79 es->err_marks[i] = 0;
80 es->err_flags[i] = 0;
81 es->err_buffer[i] = 0;
82 es->err_line[i] = -1;
83 OPENSSL_free(es->err_file[i]);
84 es->err_file[i] = NULL;
85 OPENSSL_free(es->err_func[i]);
86 es->err_func[i] = NULL;
87 }
88
89 ERR_STATE *err_get_state_int(void);
90 void ossl_err_string_int(unsigned long e, const char *func,
91 char *buf, size_t len);