Coverage Report

Created: 2026-09-12 06:55

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
603M
#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
343M
{
36
343M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
343M
    if (es->top == es->bottom)
38
24.9M
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
343M
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
35
343M
{
36
343M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
343M
    if (es->top == es->bottom)
38
24.8M
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
343M
}
Unexecuted instantiation: err_mark.c:err_get_slot
err_save.c:err_get_slot
Line
Count
Source
35
54.0k
{
36
54.0k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
37
54.0k
    if (es->top == es->bottom)
38
6.18k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
39
54.0k
}
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
1.78G
{
43
1.78G
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
1.07G
        if (deall) {
45
63.0k
            OPENSSL_free(es->err_data[i]);
46
63.0k
            es->err_data[i] = NULL;
47
63.0k
            es->err_data_size[i] = 0;
48
63.0k
            es->err_data_flags[i] = 0;
49
1.07G
        } else if (es->err_data[i] != NULL) {
50
1.07G
            es->err_data[i][0] = '\0';
51
1.07G
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
1.07G
        }
53
1.07G
    } else {
54
704M
        es->err_data[i] = NULL;
55
704M
        es->err_data_size[i] = 0;
56
704M
        es->err_data_flags[i] = 0;
57
704M
    }
58
1.78G
}
err.c:err_clear_data
Line
Count
Source
42
777M
{
43
777M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
78.7M
        if (deall) {
45
63.0k
            OPENSSL_free(es->err_data[i]);
46
63.0k
            es->err_data[i] = NULL;
47
63.0k
            es->err_data_size[i] = 0;
48
63.0k
            es->err_data_flags[i] = 0;
49
78.6M
        } else if (es->err_data[i] != NULL) {
50
78.6M
            es->err_data[i][0] = '\0';
51
78.6M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
78.6M
        }
53
699M
    } else {
54
        es->err_data[i] = NULL;
55
699M
        es->err_data_size[i] = 0;
56
699M
        es->err_data_flags[i] = 0;
57
699M
    }
58
777M
}
err_blocks.c:err_clear_data
Line
Count
Source
42
687M
{
43
687M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
683M
        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
683M
        } else if (es->err_data[i] != NULL) {
50
683M
            es->err_data[i][0] = '\0';
51
683M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
683M
        }
53
683M
    } else {
54
        es->err_data[i] = NULL;
55
4.49M
        es->err_data_size[i] = 0;
56
4.49M
        es->err_data_flags[i] = 0;
57
4.49M
    }
58
687M
}
err_mark.c:err_clear_data
Line
Count
Source
42
316M
{
43
316M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
315M
        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
315M
        } else if (es->err_data[i] != NULL) {
50
315M
            es->err_data[i][0] = '\0';
51
315M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
315M
        }
53
315M
    } else {
54
        es->err_data[i] = NULL;
55
507k
        es->err_data_size[i] = 0;
56
507k
        es->err_data_flags[i] = 0;
57
507k
    }
58
316M
}
err_save.c:err_clear_data
Line
Count
Source
42
553k
{
43
553k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
44
6.49k
        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
6.49k
        } else if (es->err_data[i] != NULL) {
50
6.49k
            es->err_data[i][0] = '\0';
51
6.49k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
52
6.49k
        }
53
546k
    } else {
54
        es->err_data[i] = NULL;
55
546k
        es->err_data_size[i] = 0;
56
546k
        es->err_data_flags[i] = 0;
57
546k
    }
58
553k
}
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
343M
{
63
343M
    es->err_buffer[i] = lib == ERR_LIB_SYS
64
343M
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
65
343M
        : ERR_PACK(lib, 0, reason);
66
343M
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
62
343M
{
63
343M
    es->err_buffer[i] = lib == ERR_LIB_SYS
64
343M
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
65
343M
        : ERR_PACK(lib, 0, reason);
66
343M
}
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
343M
{
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
343M
    OPENSSL_free(es->err_file[i]);
77
343M
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
343M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
343M
                  NULL, 0))
81
343M
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
343M
        strcpy(es->err_file[i], file);
84
85
343M
    es->err_line[i] = line;
86
343M
    OPENSSL_free(es->err_func[i]);
87
343M
    if (fn == NULL || fn[0] == '\0')
88
7.25k
        es->err_func[i] = NULL;
89
343M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
343M
                  NULL, 0))
91
343M
        != NULL)
92
343M
        strcpy(es->err_func[i], fn);
93
343M
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
71
343M
{
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
343M
    OPENSSL_free(es->err_file[i]);
77
343M
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
343M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
343M
                  NULL, 0))
81
343M
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
343M
        strcpy(es->err_file[i], file);
84
85
343M
    es->err_line[i] = line;
86
343M
    OPENSSL_free(es->err_func[i]);
87
343M
    if (fn == NULL || fn[0] == '\0')
88
7.25k
        es->err_func[i] = NULL;
89
343M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
343M
                  NULL, 0))
91
343M
        != NULL)
92
343M
        strcpy(es->err_func[i], fn);
93
343M
}
Unexecuted instantiation: err_mark.c:err_set_debug
err_save.c:err_set_debug
Line
Count
Source
71
54.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
54.0k
    OPENSSL_free(es->err_file[i]);
77
54.0k
    if (file == NULL || file[0] == '\0')
78
0
        es->err_file[i] = NULL;
79
54.0k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
80
54.0k
                  NULL, 0))
81
54.0k
        != NULL)
82
        /* We cannot use OPENSSL_strdup due to possible recursion */
83
54.0k
        strcpy(es->err_file[i], file);
84
85
54.0k
    es->err_line[i] = line;
86
54.0k
    OPENSSL_free(es->err_func[i]);
87
54.0k
    if (fn == NULL || fn[0] == '\0')
88
0
        es->err_func[i] = NULL;
89
54.0k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
90
54.0k
                  NULL, 0))
91
54.0k
        != NULL)
92
54.0k
        strcpy(es->err_func[i], fn);
93
54.0k
}
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
16.0M
{
98
16.0M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
12.8M
        OPENSSL_free(es->err_data[i]);
100
16.0M
    es->err_data[i] = data;
101
16.0M
    es->err_data_size[i] = datasz;
102
16.0M
    es->err_data_flags[i] = flags;
103
16.0M
}
err.c:err_set_data
Line
Count
Source
97
12.9M
{
98
12.9M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
12.8M
        OPENSSL_free(es->err_data[i]);
100
12.9M
    es->err_data[i] = data;
101
12.9M
    es->err_data_size[i] = datasz;
102
12.9M
    es->err_data_flags[i] = flags;
103
12.9M
}
err_blocks.c:err_set_data
Line
Count
Source
97
3.06M
{
98
3.06M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
0
        OPENSSL_free(es->err_data[i]);
100
3.06M
    es->err_data[i] = data;
101
3.06M
    es->err_data_size[i] = datasz;
102
3.06M
    es->err_data_flags[i] = flags;
103
3.06M
}
Unexecuted instantiation: err_mark.c:err_set_data
err_save.c:err_set_data
Line
Count
Source
97
45.0k
{
98
45.0k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
99
2.70k
        OPENSSL_free(es->err_data[i]);
100
45.0k
    es->err_data[i] = data;
101
45.0k
    es->err_data_size[i] = datasz;
102
45.0k
    es->err_data_flags[i] = flags;
103
45.0k
}
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.42G
{
107
1.42G
    err_clear_data(es, i, (deall));
108
1.42G
    es->err_marks[i] = 0;
109
1.42G
    es->err_flags[i] = 0;
110
1.42G
    es->err_buffer[i] = 0;
111
1.42G
    es->err_line[i] = -1;
112
1.42G
    OPENSSL_free(es->err_file[i]);
113
1.42G
    es->err_file[i] = NULL;
114
1.42G
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
1.42G
}
err.c:err_clear
Line
Count
Source
106
765M
{
107
765M
    err_clear_data(es, i, (deall));
108
765M
    es->err_marks[i] = 0;
109
765M
    es->err_flags[i] = 0;
110
765M
    es->err_buffer[i] = 0;
111
765M
    es->err_line[i] = -1;
112
765M
    OPENSSL_free(es->err_file[i]);
113
765M
    es->err_file[i] = NULL;
114
765M
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
765M
}
err_blocks.c:err_clear
Line
Count
Source
106
343M
{
107
343M
    err_clear_data(es, i, (deall));
108
343M
    es->err_marks[i] = 0;
109
343M
    es->err_flags[i] = 0;
110
343M
    es->err_buffer[i] = 0;
111
343M
    es->err_line[i] = -1;
112
343M
    OPENSSL_free(es->err_file[i]);
113
343M
    es->err_file[i] = NULL;
114
343M
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
343M
}
err_mark.c:err_clear
Line
Count
Source
106
316M
{
107
316M
    err_clear_data(es, i, (deall));
108
316M
    es->err_marks[i] = 0;
109
316M
    es->err_flags[i] = 0;
110
316M
    es->err_buffer[i] = 0;
111
316M
    es->err_line[i] = -1;
112
316M
    OPENSSL_free(es->err_file[i]);
113
316M
    es->err_file[i] = NULL;
114
316M
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
316M
}
err_save.c:err_clear
Line
Count
Source
106
544k
{
107
544k
    err_clear_data(es, i, (deall));
108
544k
    es->err_marks[i] = 0;
109
544k
    es->err_flags[i] = 0;
110
544k
    es->err_buffer[i] = 0;
111
544k
    es->err_line[i] = -1;
112
544k
    OPENSSL_free(es->err_file[i]);
113
544k
    es->err_file[i] = NULL;
114
544k
    OPENSSL_free(es->err_func[i]);
115
    es->err_func[i] = NULL;
116
544k
}
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) */