Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/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
843M
#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
476M
{
36
476M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
476M
    if (es->top == es->bottom)
38
32.2M
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
476M
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
35
476M
{
36
476M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
476M
    if (es->top == es->bottom)
38
32.2M
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
476M
}
Unexecuted instantiation: err_mark.c:err_get_slot
err_save.c:err_get_slot
Line
Count
Source
35
67.1k
{
36
67.1k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
67.1k
    if (es->top == es->bottom)
38
4.76k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
67.1k
}
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
2.45G
{
43
2.45G
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
1.50G
        if (deall) {
45
81.4k
            OPENSSL_free(es->err_data[i]);
46
81.4k
            es->err_data[i] = NULL;
47
81.4k
            es->err_data_size[i] = 0;
48
81.4k
            es->err_data_flags[i] = 0;
49
1.50G
        } else if (es->err_data[i] != NULL) {
50
1.50G
            es->err_data[i][0] = '\0';
51
1.50G
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
1.50G
        }
53
1.50G
    } else {
54
949M
        es->err_data[i] = NULL;
55
949M
        es->err_data_size[i] = 0;
56
949M
        es->err_data_flags[i] = 0;
57
949M
    }
58
2.45G
}
err.c:err_clear_data
Line
Count
Source
42
1.06G
{
43
1.06G
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
125M
        if (deall) {
45
81.4k
            OPENSSL_free(es->err_data[i]);
46
81.4k
            es->err_data[i] = NULL;
47
81.4k
            es->err_data_size[i] = 0;
48
81.4k
            es->err_data_flags[i] = 0;
49
125M
        } else if (es->err_data[i] != NULL) {
50
125M
            es->err_data[i][0] = '\0';
51
125M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
125M
        }
53
936M
    } else {
54
        es->err_data[i] = NULL;
55
936M
        es->err_data_size[i] = 0;
56
936M
        es->err_data_flags[i] = 0;
57
936M
    }
58
1.06G
}
err_blocks.c:err_clear_data
Line
Count
Source
42
953M
{
43
953M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
943M
        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
943M
        } else if (es->err_data[i] != NULL) {
50
943M
            es->err_data[i][0] = '\0';
51
943M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
943M
        }
53
943M
    } else {
54
        es->err_data[i] = NULL;
55
9.83M
        es->err_data_size[i] = 0;
56
9.83M
        es->err_data_flags[i] = 0;
57
9.83M
    }
58
953M
}
err_mark.c:err_clear_data
Line
Count
Source
42
441M
{
43
441M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
438M
        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
438M
        } else if (es->err_data[i] != NULL) {
50
438M
            es->err_data[i][0] = '\0';
51
438M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
438M
        }
53
438M
    } else {
54
        es->err_data[i] = NULL;
55
2.63M
        es->err_data_size[i] = 0;
56
2.63M
        es->err_data_flags[i] = 0;
57
2.63M
    }
58
441M
}
err_save.c:err_clear_data
Line
Count
Source
42
703k
{
43
703k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
4.59k
        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
4.59k
        } else if (es->err_data[i] != NULL) {
50
4.59k
            es->err_data[i][0] = '\0';
51
4.59k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
4.59k
        }
53
698k
    } else {
54
        es->err_data[i] = NULL;
55
698k
        es->err_data_size[i] = 0;
56
698k
        es->err_data_flags[i] = 0;
57
698k
    }
58
703k
}
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
476M
{
63
476M
    es->err_buffer[i] = lib == ERR_LIB_SYS
64
476M
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
65
476M
        : ERR_PACK(lib, 0, reason);
66
476M
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
62
476M
{
63
476M
    es->err_buffer[i] = lib == ERR_LIB_SYS
64
476M
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
65
476M
        : ERR_PACK(lib, 0, reason);
66
476M
}
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
476M
{
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
476M
    OPENSSL_free(es->err_file[i]);
77
476M
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
476M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
476M
                  NULL, 0))
81
476M
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
476M
        strcpy(es->err_file[i], file);
84
85
476M
    es->err_line[i] = line;
86
476M
    OPENSSL_free(es->err_func[i]);
87
476M
    if (fn == NULL || fn[0] == '\0')
88
8.86k
        es->err_func[i] = NULL;
89
476M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
476M
                  NULL, 0))
91
476M
        != NULL)
92
476M
        strcpy(es->err_func[i], fn);
93
476M
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
71
476M
{
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
476M
    OPENSSL_free(es->err_file[i]);
77
476M
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
476M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
476M
                  NULL, 0))
81
476M
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
476M
        strcpy(es->err_file[i], file);
84
85
476M
    es->err_line[i] = line;
86
476M
    OPENSSL_free(es->err_func[i]);
87
476M
    if (fn == NULL || fn[0] == '\0')
88
8.86k
        es->err_func[i] = NULL;
89
476M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
476M
                  NULL, 0))
91
476M
        != NULL)
92
476M
        strcpy(es->err_func[i], fn);
93
476M
}
Unexecuted instantiation: err_mark.c:err_set_debug
err_save.c:err_set_debug
Line
Count
Source
71
67.1k
{
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
67.1k
    OPENSSL_free(es->err_file[i]);
77
67.1k
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
67.1k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
67.1k
                  NULL, 0))
81
67.1k
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
67.1k
        strcpy(es->err_file[i], file);
84
85
67.1k
    es->err_line[i] = line;
86
67.1k
    OPENSSL_free(es->err_func[i]);
87
67.1k
    if (fn == NULL || fn[0] == '\0')
88
0
        es->err_func[i] = NULL;
89
67.1k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
67.1k
                  NULL, 0))
91
67.1k
        != NULL)
92
67.1k
        strcpy(es->err_func[i], fn);
93
67.1k
}
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.7M
{
98
20.7M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
16.8M
        OPENSSL_free(es->err_data[i]);
100
20.7M
    es->err_data[i] = data;
101
20.7M
    es->err_data_size[i] = datasz;
102
20.7M
    es->err_data_flags[i] = flags;
103
20.7M
}
err.c:err_set_data
Line
Count
Source
97
16.8M
{
98
16.8M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
16.8M
        OPENSSL_free(es->err_data[i]);
100
16.8M
    es->err_data[i] = data;
101
16.8M
    es->err_data_size[i] = datasz;
102
16.8M
    es->err_data_flags[i] = flags;
103
16.8M
}
err_blocks.c:err_set_data
Line
Count
Source
97
3.87M
{
98
3.87M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
0
        OPENSSL_free(es->err_data[i]);
100
3.87M
    es->err_data[i] = data;
101
3.87M
    es->err_data_size[i] = datasz;
102
3.87M
    es->err_data_flags[i] = flags;
103
3.87M
}
Unexecuted instantiation: err_mark.c:err_set_data
err_save.c:err_set_data
Line
Count
Source
97
57.7k
{
98
57.7k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
2.56k
        OPENSSL_free(es->err_data[i]);
100
57.7k
    es->err_data[i] = data;
101
57.7k
    es->err_data_size[i] = datasz;
102
57.7k
    es->err_data_flags[i] = flags;
103
57.7k
}
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
1.96G
{
107
1.96G
    err_clear_data(es, i, (deall));
108
1.96G
    es->err_marks[i] = 0;
109
1.96G
    es->err_flags[i] = 0;
110
1.96G
    es->err_buffer[i] = 0;
111
1.96G
    es->err_line[i] = -1;
112
1.96G
    OPENSSL_free(es->err_file[i]);
113
1.96G
    es->err_file[i] = NULL;
114
1.96G
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
1.96G
}
err.c:err_clear
Line
Count
Source
106
1.04G
{
107
1.04G
    err_clear_data(es, i, (deall));
108
1.04G
    es->err_marks[i] = 0;
109
1.04G
    es->err_flags[i] = 0;
110
1.04G
    es->err_buffer[i] = 0;
111
1.04G
    es->err_line[i] = -1;
112
1.04G
    OPENSSL_free(es->err_file[i]);
113
1.04G
    es->err_file[i] = NULL;
114
1.04G
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
1.04G
}
err_blocks.c:err_clear
Line
Count
Source
106
476M
{
107
476M
    err_clear_data(es, i, (deall));
108
476M
    es->err_marks[i] = 0;
109
476M
    es->err_flags[i] = 0;
110
476M
    es->err_buffer[i] = 0;
111
476M
    es->err_line[i] = -1;
112
476M
    OPENSSL_free(es->err_file[i]);
113
476M
    es->err_file[i] = NULL;
114
476M
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
476M
}
err_mark.c:err_clear
Line
Count
Source
106
441M
{
107
441M
    err_clear_data(es, i, (deall));
108
441M
    es->err_marks[i] = 0;
109
441M
    es->err_flags[i] = 0;
110
441M
    es->err_buffer[i] = 0;
111
441M
    es->err_line[i] = -1;
112
441M
    OPENSSL_free(es->err_file[i]);
113
441M
    es->err_file[i] = NULL;
114
441M
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
441M
}
err_save.c:err_clear
Line
Count
Source
106
693k
{
107
693k
    err_clear_data(es, i, (deall));
108
693k
    es->err_marks[i] = 0;
109
693k
    es->err_flags[i] = 0;
110
693k
    es->err_buffer[i] = 0;
111
693k
    es->err_line[i] = -1;
112
693k
    OPENSSL_free(es->err_file[i]);
113
693k
    es->err_file[i] = NULL;
114
693k
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
693k
}
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) */