Coverage Report

Created: 2023-09-25 06:41

/src/openssl/crypto/err/err_local.h
Line
Count
Source (jump to first uncovered line)
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
14
static ossl_inline void err_get_slot(ERR_STATE *es)
15
533k
{
16
533k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
533k
    if (es->top == es->bottom)
18
261k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
533k
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
533k
{
16
533k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
533k
    if (es->top == es->bottom)
18
261k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
533k
}
Unexecuted instantiation: err_mark.c:err_get_slot
Unexecuted instantiation: err_save.c:err_get_slot
Unexecuted instantiation: err_prn.c:err_get_slot
20
21
static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall)
22
1.60M
{
23
1.60M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1.57M
        if (deall) {
25
17
            OPENSSL_free(es->err_data[i]);
26
17
            es->err_data[i] = NULL;
27
17
            es->err_data_size[i] = 0;
28
17
            es->err_data_flags[i] = 0;
29
1.57M
        } else if (es->err_data[i] != NULL) {
30
1.57M
            es->err_data[i][0] = '\0';
31
1.57M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1.57M
        }
33
1.57M
    } else {
34
30.3k
        es->err_data[i] = NULL;
35
30.3k
        es->err_data_size[i] = 0;
36
30.3k
        es->err_data_flags[i] = 0;
37
30.3k
    }
38
1.60M
}
err.c:err_clear_data
Line
Count
Source
22
314k
{
23
314k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
292k
        if (deall) {
25
17
            OPENSSL_free(es->err_data[i]);
26
17
            es->err_data[i] = NULL;
27
17
            es->err_data_size[i] = 0;
28
17
            es->err_data_flags[i] = 0;
29
292k
        } else if (es->err_data[i] != NULL) {
30
292k
            es->err_data[i][0] = '\0';
31
292k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
292k
        }
33
292k
    } else {
34
21.6k
        es->err_data[i] = NULL;
35
21.6k
        es->err_data_size[i] = 0;
36
21.6k
        es->err_data_flags[i] = 0;
37
21.6k
    }
38
314k
}
err_blocks.c:err_clear_data
Line
Count
Source
22
1.06M
{
23
1.06M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1.05M
        if (deall) {
25
0
            OPENSSL_free(es->err_data[i]);
26
0
            es->err_data[i] = NULL;
27
0
            es->err_data_size[i] = 0;
28
0
            es->err_data_flags[i] = 0;
29
1.05M
        } else if (es->err_data[i] != NULL) {
30
1.05M
            es->err_data[i][0] = '\0';
31
1.05M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1.05M
        }
33
1.05M
    } else {
34
8.61k
        es->err_data[i] = NULL;
35
8.61k
        es->err_data_size[i] = 0;
36
8.61k
        es->err_data_flags[i] = 0;
37
8.61k
    }
38
1.06M
}
err_mark.c:err_clear_data
Line
Count
Source
22
222k
{
23
222k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
222k
        if (deall) {
25
0
            OPENSSL_free(es->err_data[i]);
26
0
            es->err_data[i] = NULL;
27
0
            es->err_data_size[i] = 0;
28
0
            es->err_data_flags[i] = 0;
29
222k
        } else if (es->err_data[i] != NULL) {
30
222k
            es->err_data[i][0] = '\0';
31
222k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
222k
        }
33
222k
    } else {
34
45
        es->err_data[i] = NULL;
35
45
        es->err_data_size[i] = 0;
36
45
        es->err_data_flags[i] = 0;
37
45
    }
38
222k
}
Unexecuted instantiation: err_save.c:err_clear_data
Unexecuted instantiation: err_prn.c:err_clear_data
39
40
static ossl_inline void err_set_error(ERR_STATE *es, size_t i,
41
                                      int lib, int reason)
42
533k
{
43
533k
    es->err_buffer[i] =
44
533k
        lib == ERR_LIB_SYS
45
533k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
533k
        : ERR_PACK(lib, 0, reason);
47
533k
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
533k
{
43
533k
    es->err_buffer[i] =
44
533k
        lib == ERR_LIB_SYS
45
533k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
533k
        : ERR_PACK(lib, 0, reason);
47
533k
}
Unexecuted instantiation: err_mark.c:err_set_error
Unexecuted instantiation: err_save.c:err_set_error
Unexecuted instantiation: err_prn.c:err_set_error
48
49
static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
50
                                      const char *file, int line,
51
                                      const char *fn)
52
533k
{
53
    /*
54
     * We dup the file and fn strings because they may be provider owned. If the
55
     * provider gets unloaded, they may not be valid anymore.
56
     */
57
533k
    OPENSSL_free(es->err_file[i]);
58
533k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
533k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
533k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
533k
        strcpy(es->err_file[i], file);
64
65
533k
    es->err_line[i] = line;
66
533k
    OPENSSL_free(es->err_func[i]);
67
533k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
533k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
533k
                                              NULL, 0)) != NULL)
71
533k
        strcpy(es->err_func[i], fn);
72
533k
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
52
533k
{
53
    /*
54
     * We dup the file and fn strings because they may be provider owned. If the
55
     * provider gets unloaded, they may not be valid anymore.
56
     */
57
533k
    OPENSSL_free(es->err_file[i]);
58
533k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
533k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
533k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
533k
        strcpy(es->err_file[i], file);
64
65
533k
    es->err_line[i] = line;
66
533k
    OPENSSL_free(es->err_func[i]);
67
533k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
533k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
533k
                                              NULL, 0)) != NULL)
71
533k
        strcpy(es->err_func[i], fn);
72
533k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_save.c:err_set_debug
Unexecuted instantiation: err_prn.c:err_set_debug
73
74
static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
75
                                     void *data, size_t datasz, int flags)
76
131k
{
77
131k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
122k
        OPENSSL_free(es->err_data[i]);
79
131k
    es->err_data[i] = data;
80
131k
    es->err_data_size[i] = datasz;
81
131k
    es->err_data_flags[i] = flags;
82
131k
}
err.c:err_set_data
Line
Count
Source
76
122k
{
77
122k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
122k
        OPENSSL_free(es->err_data[i]);
79
122k
    es->err_data[i] = data;
80
122k
    es->err_data_size[i] = datasz;
81
122k
    es->err_data_flags[i] = flags;
82
122k
}
err_blocks.c:err_set_data
Line
Count
Source
76
8.46k
{
77
8.46k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
0
        OPENSSL_free(es->err_data[i]);
79
8.46k
    es->err_data[i] = data;
80
8.46k
    es->err_data_size[i] = datasz;
81
8.46k
    es->err_data_flags[i] = flags;
82
8.46k
}
Unexecuted instantiation: err_mark.c:err_set_data
Unexecuted instantiation: err_save.c:err_set_data
Unexecuted instantiation: err_prn.c:err_set_data
83
84
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
85
947k
{
86
947k
    err_clear_data(es, i, (deall));
87
947k
    es->err_marks[i] = 0;
88
947k
    es->err_flags[i] = 0;
89
947k
    es->err_buffer[i] = 0;
90
947k
    es->err_line[i] = -1;
91
947k
    OPENSSL_free(es->err_file[i]);
92
947k
    es->err_file[i] = NULL;
93
947k
    OPENSSL_free(es->err_func[i]);
94
947k
    es->err_func[i] = NULL;
95
947k
}
err.c:err_clear
Line
Count
Source
85
191k
{
86
191k
    err_clear_data(es, i, (deall));
87
191k
    es->err_marks[i] = 0;
88
191k
    es->err_flags[i] = 0;
89
191k
    es->err_buffer[i] = 0;
90
191k
    es->err_line[i] = -1;
91
191k
    OPENSSL_free(es->err_file[i]);
92
191k
    es->err_file[i] = NULL;
93
191k
    OPENSSL_free(es->err_func[i]);
94
191k
    es->err_func[i] = NULL;
95
191k
}
err_blocks.c:err_clear
Line
Count
Source
85
533k
{
86
533k
    err_clear_data(es, i, (deall));
87
533k
    es->err_marks[i] = 0;
88
533k
    es->err_flags[i] = 0;
89
533k
    es->err_buffer[i] = 0;
90
533k
    es->err_line[i] = -1;
91
533k
    OPENSSL_free(es->err_file[i]);
92
533k
    es->err_file[i] = NULL;
93
533k
    OPENSSL_free(es->err_func[i]);
94
533k
    es->err_func[i] = NULL;
95
533k
}
err_mark.c:err_clear
Line
Count
Source
85
222k
{
86
222k
    err_clear_data(es, i, (deall));
87
222k
    es->err_marks[i] = 0;
88
222k
    es->err_flags[i] = 0;
89
222k
    es->err_buffer[i] = 0;
90
222k
    es->err_line[i] = -1;
91
222k
    OPENSSL_free(es->err_file[i]);
92
222k
    es->err_file[i] = NULL;
93
222k
    OPENSSL_free(es->err_func[i]);
94
222k
    es->err_func[i] = NULL;
95
222k
}
Unexecuted instantiation: err_save.c:err_clear
Unexecuted instantiation: err_prn.c:err_clear
96
97
ERR_STATE *ossl_err_get_state_int(void);
98
void ossl_err_string_int(unsigned long e, const char *func,
99
                         char *buf, size_t len);