Coverage Report

Created: 2026-10-28 06:28

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