Coverage Report

Created: 2026-09-12 06:55

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