Coverage Report

Created: 2026-03-09 06:55

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-2023 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
94.3k
#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
47.1k
{
33
47.1k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
34
47.1k
    if (es->top == es->bottom)
35
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
36
47.1k
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
32
47.1k
{
33
47.1k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
34
47.1k
    if (es->top == es->bottom)
35
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
36
47.1k
}
Unexecuted instantiation: err_mark.c:err_get_slot
Unexecuted instantiation: err_save.c:err_get_slot
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
161k
{
40
161k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
41
160k
        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
160k
        } else if (es->err_data[i] != NULL) {
47
160k
            es->err_data[i][0] = '\0';
48
160k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
49
160k
        }
50
160k
    } else {
51
1.19k
        es->err_data[i] = NULL;
52
1.19k
        es->err_data_size[i] = 0;
53
1.19k
        es->err_data_flags[i] = 0;
54
1.19k
    }
55
161k
}
err.c:err_clear_data
Line
Count
Source
39
67.2k
{
40
67.2k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
41
66.9k
        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
66.9k
        } else if (es->err_data[i] != NULL) {
47
66.9k
            es->err_data[i][0] = '\0';
48
66.9k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
49
66.9k
        }
50
66.9k
    } else {
51
        es->err_data[i] = NULL;
52
355
        es->err_data_size[i] = 0;
53
355
        es->err_data_flags[i] = 0;
54
355
    }
55
67.2k
}
err_blocks.c:err_clear_data
Line
Count
Source
39
94.3k
{
40
94.3k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
41
93.5k
        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
93.5k
        } else if (es->err_data[i] != NULL) {
47
93.5k
            es->err_data[i][0] = '\0';
48
93.5k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
49
93.5k
        }
50
93.5k
    } else {
51
        es->err_data[i] = NULL;
52
806
        es->err_data_size[i] = 0;
53
806
        es->err_data_flags[i] = 0;
54
806
    }
55
94.3k
}
err_mark.c:err_clear_data
Line
Count
Source
39
48
{
40
48
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
41
16
        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
16
        } else if (es->err_data[i] != NULL) {
47
16
            es->err_data[i][0] = '\0';
48
16
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
49
16
        }
50
32
    } else {
51
        es->err_data[i] = NULL;
52
32
        es->err_data_size[i] = 0;
53
32
        es->err_data_flags[i] = 0;
54
32
    }
55
48
}
Unexecuted instantiation: err_save.c:err_clear_data
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
47.1k
{
60
47.1k
    es->err_buffer[i] = lib == ERR_LIB_SYS
61
47.1k
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
62
47.1k
        : ERR_PACK(lib, 0, reason);
63
47.1k
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
59
47.1k
{
60
47.1k
    es->err_buffer[i] = lib == ERR_LIB_SYS
61
47.1k
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
62
47.1k
        : ERR_PACK(lib, 0, reason);
63
47.1k
}
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
47.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
47.1k
    OPENSSL_free(es->err_file[i]);
74
47.1k
    if (file == NULL || file[0] == '\0')
75
0
        es->err_file[i] = NULL;
76
47.1k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
77
47.1k
                  NULL, 0))
78
47.1k
        != NULL)
79
        /* We cannot use OPENSSL_strdup due to possible recursion */
80
47.1k
        strcpy(es->err_file[i], file);
81
82
47.1k
    es->err_line[i] = line;
83
47.1k
    OPENSSL_free(es->err_func[i]);
84
47.1k
    if (fn == NULL || fn[0] == '\0')
85
0
        es->err_func[i] = NULL;
86
47.1k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
87
47.1k
                  NULL, 0))
88
47.1k
        != NULL)
89
47.1k
        strcpy(es->err_func[i], fn);
90
47.1k
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
68
47.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
47.1k
    OPENSSL_free(es->err_file[i]);
74
47.1k
    if (file == NULL || file[0] == '\0')
75
0
        es->err_file[i] = NULL;
76
47.1k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
77
47.1k
                  NULL, 0))
78
47.1k
        != NULL)
79
        /* We cannot use OPENSSL_strdup due to possible recursion */
80
47.1k
        strcpy(es->err_file[i], file);
81
82
47.1k
    es->err_line[i] = line;
83
47.1k
    OPENSSL_free(es->err_func[i]);
84
47.1k
    if (fn == NULL || fn[0] == '\0')
85
0
        es->err_func[i] = NULL;
86
47.1k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
87
47.1k
                  NULL, 0))
88
47.1k
        != NULL)
89
47.1k
        strcpy(es->err_func[i], fn);
90
47.1k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_save.c:err_set_debug
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.1k
{
95
20.1k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
96
20.0k
        OPENSSL_free(es->err_data[i]);
97
20.1k
    es->err_data[i] = data;
98
20.1k
    es->err_data_size[i] = datasz;
99
20.1k
    es->err_data_flags[i] = flags;
100
20.1k
}
err.c:err_set_data
Line
Count
Source
94
20.1k
{
95
20.1k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
96
20.0k
        OPENSSL_free(es->err_data[i]);
97
20.1k
    es->err_data[i] = data;
98
20.1k
    es->err_data_size[i] = datasz;
99
20.1k
    es->err_data_flags[i] = flags;
100
20.1k
}
err_blocks.c:err_set_data
Line
Count
Source
94
16
{
95
16
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
96
0
        OPENSSL_free(es->err_data[i]);
97
16
    es->err_data[i] = data;
98
16
    es->err_data_size[i] = datasz;
99
16
    es->err_data_flags[i] = flags;
100
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
101
102
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
103
47.2k
{
104
47.2k
    err_clear_data(es, i, (deall));
105
47.2k
    es->err_marks[i] = 0;
106
47.2k
    es->err_flags[i] = 0;
107
47.2k
    es->err_buffer[i] = 0;
108
47.2k
    es->err_line[i] = -1;
109
47.2k
    OPENSSL_free(es->err_file[i]);
110
47.2k
    es->err_file[i] = NULL;
111
47.2k
    OPENSSL_free(es->err_func[i]);
112
    es->err_func[i] = NULL;
113
47.2k
}
Unexecuted instantiation: err.c:err_clear
err_blocks.c:err_clear
Line
Count
Source
103
47.1k
{
104
47.1k
    err_clear_data(es, i, (deall));
105
47.1k
    es->err_marks[i] = 0;
106
47.1k
    es->err_flags[i] = 0;
107
47.1k
    es->err_buffer[i] = 0;
108
47.1k
    es->err_line[i] = -1;
109
47.1k
    OPENSSL_free(es->err_file[i]);
110
47.1k
    es->err_file[i] = NULL;
111
47.1k
    OPENSSL_free(es->err_func[i]);
112
    es->err_func[i] = NULL;
113
47.1k
}
err_mark.c:err_clear
Line
Count
Source
103
48
{
104
48
    err_clear_data(es, i, (deall));
105
48
    es->err_marks[i] = 0;
106
48
    es->err_flags[i] = 0;
107
48
    es->err_buffer[i] = 0;
108
48
    es->err_line[i] = -1;
109
48
    OPENSSL_free(es->err_file[i]);
110
48
    es->err_file[i] = NULL;
111
48
    OPENSSL_free(es->err_func[i]);
112
    es->err_func[i] = NULL;
113
48
}
Unexecuted instantiation: err_save.c:err_clear
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);