Coverage Report

Created: 2026-03-08 06:31

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