Coverage Report

Created: 2026-05-20 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/err/err_local.h
Line
Count
Source
1
/*
2
 * Copyright 1995-2026 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
#if !defined(OSSL_LIBCRYPTO_ERR_ERR_LOCAL_H)
11
#define OSSL_LIBCRYPTO_ERR_ERR_LOCAL_H
12
13
#include <string.h>
14
#include <openssl/err.h>
15
#include <openssl/e_os2.h>
16
#include "internal/err.h"
17
18
#define ERR_FLAG_MARK 0x01
19
94.1k
#define ERR_FLAG_CLEAR 0x02
20
21
struct err_state_st {
22
    int err_flags[ERR_NUM_ERRORS];
23
    int err_marks[ERR_NUM_ERRORS];
24
    unsigned long err_buffer[ERR_NUM_ERRORS];
25
    char *err_data[ERR_NUM_ERRORS];
26
    size_t err_data_size[ERR_NUM_ERRORS];
27
    int err_data_flags[ERR_NUM_ERRORS];
28
    char *err_file[ERR_NUM_ERRORS];
29
    int err_line[ERR_NUM_ERRORS];
30
    char *err_func[ERR_NUM_ERRORS];
31
    int top, bottom;
32
};
33
34
static ossl_inline void err_get_slot(ERR_STATE *es)
35
47.0k
{
36
47.0k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
47.0k
    if (es->top == es->bottom)
38
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
47.0k
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
35
47.0k
{
36
47.0k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
47.0k
    if (es->top == es->bottom)
38
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
47.0k
}
Unexecuted instantiation: err_mark.c:err_get_slot
Unexecuted instantiation: err_save.c:err_get_slot
Unexecuted instantiation: err_prn.c:err_get_slot
40
41
static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall)
42
161k
{
43
161k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
160k
        if (deall) {
45
0
            OPENSSL_free(es->err_data[i]);
46
0
            es->err_data[i] = NULL;
47
0
            es->err_data_size[i] = 0;
48
0
            es->err_data_flags[i] = 0;
49
160k
        } else if (es->err_data[i] != NULL) {
50
160k
            es->err_data[i][0] = '\0';
51
160k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
160k
        }
53
160k
    } else {
54
1.11k
        es->err_data[i] = NULL;
55
1.11k
        es->err_data_size[i] = 0;
56
1.11k
        es->err_data_flags[i] = 0;
57
1.11k
    }
58
161k
}
err.c:err_clear_data
Line
Count
Source
42
67.1k
{
43
67.1k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
66.8k
        if (deall) {
45
0
            OPENSSL_free(es->err_data[i]);
46
0
            es->err_data[i] = NULL;
47
0
            es->err_data_size[i] = 0;
48
0
            es->err_data_flags[i] = 0;
49
66.8k
        } else if (es->err_data[i] != NULL) {
50
66.8k
            es->err_data[i][0] = '\0';
51
66.8k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
66.8k
        }
53
66.8k
    } else {
54
        es->err_data[i] = NULL;
55
329
        es->err_data_size[i] = 0;
56
329
        es->err_data_flags[i] = 0;
57
329
    }
58
67.1k
}
err_blocks.c:err_clear_data
Line
Count
Source
42
94.1k
{
43
94.1k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
93.4k
        if (deall) {
45
0
            OPENSSL_free(es->err_data[i]);
46
0
            es->err_data[i] = NULL;
47
0
            es->err_data_size[i] = 0;
48
0
            es->err_data_flags[i] = 0;
49
93.4k
        } else if (es->err_data[i] != NULL) {
50
93.4k
            es->err_data[i][0] = '\0';
51
93.4k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
93.4k
        }
53
93.4k
    } else {
54
        es->err_data[i] = NULL;
55
754
        es->err_data_size[i] = 0;
56
754
        es->err_data_flags[i] = 0;
57
754
    }
58
94.1k
}
err_mark.c:err_clear_data
Line
Count
Source
42
48
{
43
48
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
16
        if (deall) {
45
0
            OPENSSL_free(es->err_data[i]);
46
0
            es->err_data[i] = NULL;
47
0
            es->err_data_size[i] = 0;
48
0
            es->err_data_flags[i] = 0;
49
16
        } else if (es->err_data[i] != NULL) {
50
16
            es->err_data[i][0] = '\0';
51
16
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
16
        }
53
32
    } else {
54
        es->err_data[i] = NULL;
55
32
        es->err_data_size[i] = 0;
56
32
        es->err_data_flags[i] = 0;
57
32
    }
58
48
}
Unexecuted instantiation: err_save.c:err_clear_data
Unexecuted instantiation: err_prn.c:err_clear_data
59
60
static ossl_inline void err_set_error(ERR_STATE *es, size_t i,
61
    int lib, int reason)
62
47.0k
{
63
47.0k
    es->err_buffer[i] = lib == ERR_LIB_SYS
64
47.0k
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
65
47.0k
        : ERR_PACK(lib, 0, reason);
66
47.0k
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
62
47.0k
{
63
47.0k
    es->err_buffer[i] = lib == ERR_LIB_SYS
64
47.0k
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
65
47.0k
        : ERR_PACK(lib, 0, reason);
66
47.0k
}
Unexecuted instantiation: err_mark.c:err_set_error
Unexecuted instantiation: err_save.c:err_set_error
Unexecuted instantiation: err_prn.c:err_set_error
67
68
static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
69
    const char *file, int line,
70
    const char *fn)
71
47.0k
{
72
    /*
73
     * We dup the file and fn strings because they may be provider owned. If the
74
     * provider gets unloaded, they may not be valid anymore.
75
     */
76
47.0k
    OPENSSL_free(es->err_file[i]);
77
47.0k
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
47.0k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
47.0k
                  NULL, 0))
81
47.0k
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
47.0k
        strcpy(es->err_file[i], file);
84
85
47.0k
    es->err_line[i] = line;
86
47.0k
    OPENSSL_free(es->err_func[i]);
87
47.0k
    if (fn == NULL || fn[0] == '\0')
88
0
        es->err_func[i] = NULL;
89
47.0k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
47.0k
                  NULL, 0))
91
47.0k
        != NULL)
92
47.0k
        strcpy(es->err_func[i], fn);
93
47.0k
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
71
47.0k
{
72
    /*
73
     * We dup the file and fn strings because they may be provider owned. If the
74
     * provider gets unloaded, they may not be valid anymore.
75
     */
76
47.0k
    OPENSSL_free(es->err_file[i]);
77
47.0k
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
47.0k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
47.0k
                  NULL, 0))
81
47.0k
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
47.0k
        strcpy(es->err_file[i], file);
84
85
47.0k
    es->err_line[i] = line;
86
47.0k
    OPENSSL_free(es->err_func[i]);
87
47.0k
    if (fn == NULL || fn[0] == '\0')
88
0
        es->err_func[i] = NULL;
89
47.0k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
47.0k
                  NULL, 0))
91
47.0k
        != NULL)
92
47.0k
        strcpy(es->err_func[i], fn);
93
47.0k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_save.c:err_set_debug
Unexecuted instantiation: err_prn.c:err_set_debug
94
95
static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
96
    void *data, size_t datasz, int flags)
97
20.1k
{
98
20.1k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
19.9k
        OPENSSL_free(es->err_data[i]);
100
20.1k
    es->err_data[i] = data;
101
20.1k
    es->err_data_size[i] = datasz;
102
20.1k
    es->err_data_flags[i] = flags;
103
20.1k
}
err.c:err_set_data
Line
Count
Source
97
20.0k
{
98
20.0k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
19.9k
        OPENSSL_free(es->err_data[i]);
100
20.0k
    es->err_data[i] = data;
101
20.0k
    es->err_data_size[i] = datasz;
102
20.0k
    es->err_data_flags[i] = flags;
103
20.0k
}
err_blocks.c:err_set_data
Line
Count
Source
97
16
{
98
16
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
0
        OPENSSL_free(es->err_data[i]);
100
16
    es->err_data[i] = data;
101
16
    es->err_data_size[i] = datasz;
102
16
    es->err_data_flags[i] = flags;
103
16
}
Unexecuted instantiation: err_mark.c:err_set_data
Unexecuted instantiation: err_save.c:err_set_data
Unexecuted instantiation: err_prn.c:err_set_data
104
105
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
106
47.1k
{
107
47.1k
    err_clear_data(es, i, (deall));
108
47.1k
    es->err_marks[i] = 0;
109
47.1k
    es->err_flags[i] = 0;
110
47.1k
    es->err_buffer[i] = 0;
111
47.1k
    es->err_line[i] = -1;
112
47.1k
    OPENSSL_free(es->err_file[i]);
113
47.1k
    es->err_file[i] = NULL;
114
47.1k
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
47.1k
}
Unexecuted instantiation: err.c:err_clear
err_blocks.c:err_clear
Line
Count
Source
106
47.0k
{
107
47.0k
    err_clear_data(es, i, (deall));
108
47.0k
    es->err_marks[i] = 0;
109
47.0k
    es->err_flags[i] = 0;
110
47.0k
    es->err_buffer[i] = 0;
111
47.0k
    es->err_line[i] = -1;
112
47.0k
    OPENSSL_free(es->err_file[i]);
113
47.0k
    es->err_file[i] = NULL;
114
47.0k
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
47.0k
}
err_mark.c:err_clear
Line
Count
Source
106
48
{
107
48
    err_clear_data(es, i, (deall));
108
48
    es->err_marks[i] = 0;
109
48
    es->err_flags[i] = 0;
110
48
    es->err_buffer[i] = 0;
111
48
    es->err_line[i] = -1;
112
48
    OPENSSL_free(es->err_file[i]);
113
48
    es->err_file[i] = NULL;
114
48
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
48
}
Unexecuted instantiation: err_save.c:err_clear
Unexecuted instantiation: err_prn.c:err_clear
117
118
ERR_STATE *ossl_err_get_state_int(int save_sys_error);
119
void ossl_err_string_int(unsigned long e, const char *func,
120
    char *buf, size_t len);
121
122
#endif /* !defined(OSSL_LIBCRYPTO_ERR_ERR_LOCAL_H) */