Coverage Report

Created: 2024-05-21 06:52

/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
2.46M
{
16
2.46M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
2.46M
    if (es->top == es->bottom)
18
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
2.46M
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
2.46M
{
16
2.46M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
2.46M
    if (es->top == es->bottom)
18
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
2.46M
}
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
7.44M
{
23
7.44M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
7.34M
        if (deall) {
25
33
            OPENSSL_free(es->err_data[i]);
26
33
            es->err_data[i] = NULL;
27
33
            es->err_data_size[i] = 0;
28
33
            es->err_data_flags[i] = 0;
29
7.34M
        } else if (es->err_data[i] != NULL) {
30
7.34M
            es->err_data[i][0] = '\0';
31
7.34M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
7.34M
        }
33
7.34M
    } else {
34
98.0k
        es->err_data[i] = NULL;
35
98.0k
        es->err_data_size[i] = 0;
36
98.0k
        es->err_data_flags[i] = 0;
37
98.0k
    }
38
7.44M
}
err.c:err_clear_data
Line
Count
Source
22
59.0k
{
23
59.0k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
13.1k
        if (deall) {
25
33
            OPENSSL_free(es->err_data[i]);
26
33
            es->err_data[i] = NULL;
27
33
            es->err_data_size[i] = 0;
28
33
            es->err_data_flags[i] = 0;
29
13.1k
        } else if (es->err_data[i] != NULL) {
30
13.1k
            es->err_data[i][0] = '\0';
31
13.1k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
13.1k
        }
33
45.8k
    } else {
34
45.8k
        es->err_data[i] = NULL;
35
45.8k
        es->err_data_size[i] = 0;
36
45.8k
        es->err_data_flags[i] = 0;
37
45.8k
    }
38
59.0k
}
err_blocks.c:err_clear_data
Line
Count
Source
22
4.92M
{
23
4.92M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
4.88M
        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
4.88M
        } else if (es->err_data[i] != NULL) {
30
4.88M
            es->err_data[i][0] = '\0';
31
4.88M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
4.88M
        }
33
4.88M
    } else {
34
43.8k
        es->err_data[i] = NULL;
35
43.8k
        es->err_data_size[i] = 0;
36
43.8k
        es->err_data_flags[i] = 0;
37
43.8k
    }
38
4.92M
}
err_mark.c:err_clear_data
Line
Count
Source
22
2.45M
{
23
2.45M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
2.45M
        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
2.45M
        } else if (es->err_data[i] != NULL) {
30
2.45M
            es->err_data[i][0] = '\0';
31
2.45M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
2.45M
        }
33
2.45M
    } else {
34
8.36k
        es->err_data[i] = NULL;
35
8.36k
        es->err_data_size[i] = 0;
36
8.36k
        es->err_data_flags[i] = 0;
37
8.36k
    }
38
2.45M
}
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
2.46M
{
43
2.46M
    es->err_buffer[i] =
44
2.46M
        lib == ERR_LIB_SYS
45
2.46M
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
2.46M
        : ERR_PACK(lib, 0, reason);
47
2.46M
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
2.46M
{
43
2.46M
    es->err_buffer[i] =
44
2.46M
        lib == ERR_LIB_SYS
45
2.46M
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
2.46M
        : ERR_PACK(lib, 0, reason);
47
2.46M
}
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
2.46M
{
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
2.46M
    OPENSSL_free(es->err_file[i]);
58
2.46M
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
2.46M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
2.46M
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
2.46M
        strcpy(es->err_file[i], file);
64
65
2.46M
    es->err_line[i] = line;
66
2.46M
    OPENSSL_free(es->err_func[i]);
67
2.46M
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
2.46M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
2.46M
                                              NULL, 0)) != NULL)
71
2.46M
        strcpy(es->err_func[i], fn);
72
2.46M
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
52
2.46M
{
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
2.46M
    OPENSSL_free(es->err_file[i]);
58
2.46M
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
2.46M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
2.46M
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
2.46M
        strcpy(es->err_file[i], file);
64
65
2.46M
    es->err_line[i] = line;
66
2.46M
    OPENSSL_free(es->err_func[i]);
67
2.46M
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
2.46M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
2.46M
                                              NULL, 0)) != NULL)
71
2.46M
        strcpy(es->err_func[i], fn);
72
2.46M
}
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
24.4k
{
77
24.4k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
2.62k
        OPENSSL_free(es->err_data[i]);
79
24.4k
    es->err_data[i] = data;
80
24.4k
    es->err_data_size[i] = datasz;
81
24.4k
    es->err_data_flags[i] = flags;
82
24.4k
}
err.c:err_set_data
Line
Count
Source
76
2.63k
{
77
2.63k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
2.62k
        OPENSSL_free(es->err_data[i]);
79
2.63k
    es->err_data[i] = data;
80
2.63k
    es->err_data_size[i] = datasz;
81
2.63k
    es->err_data_flags[i] = flags;
82
2.63k
}
err_blocks.c:err_set_data
Line
Count
Source
76
21.8k
{
77
21.8k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
0
        OPENSSL_free(es->err_data[i]);
79
21.8k
    es->err_data[i] = data;
80
21.8k
    es->err_data_size[i] = datasz;
81
21.8k
    es->err_data_flags[i] = flags;
82
21.8k
}
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
4.97M
{
86
4.97M
    err_clear_data(es, i, (deall));
87
4.97M
    es->err_marks[i] = 0;
88
4.97M
    es->err_flags[i] = 0;
89
4.97M
    es->err_buffer[i] = 0;
90
4.97M
    es->err_line[i] = -1;
91
4.97M
    OPENSSL_free(es->err_file[i]);
92
4.97M
    es->err_file[i] = NULL;
93
4.97M
    OPENSSL_free(es->err_func[i]);
94
4.97M
    es->err_func[i] = NULL;
95
4.97M
}
err.c:err_clear
Line
Count
Source
85
56.3k
{
86
56.3k
    err_clear_data(es, i, (deall));
87
56.3k
    es->err_marks[i] = 0;
88
56.3k
    es->err_flags[i] = 0;
89
56.3k
    es->err_buffer[i] = 0;
90
56.3k
    es->err_line[i] = -1;
91
56.3k
    OPENSSL_free(es->err_file[i]);
92
56.3k
    es->err_file[i] = NULL;
93
56.3k
    OPENSSL_free(es->err_func[i]);
94
56.3k
    es->err_func[i] = NULL;
95
56.3k
}
err_blocks.c:err_clear
Line
Count
Source
85
2.46M
{
86
2.46M
    err_clear_data(es, i, (deall));
87
2.46M
    es->err_marks[i] = 0;
88
2.46M
    es->err_flags[i] = 0;
89
2.46M
    es->err_buffer[i] = 0;
90
2.46M
    es->err_line[i] = -1;
91
2.46M
    OPENSSL_free(es->err_file[i]);
92
2.46M
    es->err_file[i] = NULL;
93
2.46M
    OPENSSL_free(es->err_func[i]);
94
2.46M
    es->err_func[i] = NULL;
95
2.46M
}
err_mark.c:err_clear
Line
Count
Source
85
2.45M
{
86
2.45M
    err_clear_data(es, i, (deall));
87
2.45M
    es->err_marks[i] = 0;
88
2.45M
    es->err_flags[i] = 0;
89
2.45M
    es->err_buffer[i] = 0;
90
2.45M
    es->err_line[i] = -1;
91
2.45M
    OPENSSL_free(es->err_file[i]);
92
2.45M
    es->err_file[i] = NULL;
93
2.45M
    OPENSSL_free(es->err_func[i]);
94
2.45M
    es->err_func[i] = NULL;
95
2.45M
}
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);