Coverage Report

Created: 2023-04-12 06:22

/src/openssl/crypto/err/err_local.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2021 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
4.81k
{
16
4.81k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
4.81k
    if (es->top == es->bottom)
18
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
4.81k
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
4.81k
{
16
4.81k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
4.81k
    if (es->top == es->bottom)
18
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
4.81k
}
Unexecuted instantiation: err_mark.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
16.5k
{
23
16.5k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
16.3k
        if (deall) {
25
16
            OPENSSL_free(es->err_data[i]);
26
16
            es->err_data[i] = NULL;
27
16
            es->err_data_size[i] = 0;
28
16
            es->err_data_flags[i] = 0;
29
16.3k
        } else if (es->err_data[i] != NULL) {
30
16.3k
            es->err_data[i][0] = '\0';
31
16.3k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
16.3k
        }
33
16.3k
    } else {
34
125
        es->err_data[i] = NULL;
35
125
        es->err_data_size[i] = 0;
36
125
        es->err_data_flags[i] = 0;
37
125
    }
38
16.5k
}
err.c:err_clear_data
Line
Count
Source
22
6.87k
{
23
6.87k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
6.83k
        if (deall) {
25
16
            OPENSSL_free(es->err_data[i]);
26
16
            es->err_data[i] = NULL;
27
16
            es->err_data_size[i] = 0;
28
16
            es->err_data_flags[i] = 0;
29
6.81k
        } else if (es->err_data[i] != NULL) {
30
6.81k
            es->err_data[i][0] = '\0';
31
6.81k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
6.81k
        }
33
6.83k
    } else {
34
39
        es->err_data[i] = NULL;
35
39
        es->err_data_size[i] = 0;
36
39
        es->err_data_flags[i] = 0;
37
39
    }
38
6.87k
}
err_blocks.c:err_clear_data
Line
Count
Source
22
9.63k
{
23
9.63k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
9.54k
        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
9.54k
        } else if (es->err_data[i] != NULL) {
30
9.54k
            es->err_data[i][0] = '\0';
31
9.54k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
9.54k
        }
33
9.54k
    } else {
34
84
        es->err_data[i] = NULL;
35
84
        es->err_data_size[i] = 0;
36
84
        es->err_data_flags[i] = 0;
37
84
    }
38
9.63k
}
err_mark.c:err_clear_data
Line
Count
Source
22
3
{
23
3
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1
        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
        } else if (es->err_data[i] != NULL) {
30
1
            es->err_data[i][0] = '\0';
31
1
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1
        }
33
2
    } else {
34
2
        es->err_data[i] = NULL;
35
2
        es->err_data_size[i] = 0;
36
2
        es->err_data_flags[i] = 0;
37
2
    }
38
3
}
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
4.81k
{
43
4.81k
    es->err_buffer[i] =
44
4.81k
        lib == ERR_LIB_SYS
45
4.81k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
4.81k
        : ERR_PACK(lib, 0, reason);
47
4.81k
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
4.81k
{
43
4.81k
    es->err_buffer[i] =
44
4.81k
        lib == ERR_LIB_SYS
45
4.81k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
4.81k
        : ERR_PACK(lib, 0, reason);
47
4.81k
}
Unexecuted instantiation: err_mark.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
4.81k
{
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
4.81k
    OPENSSL_free(es->err_file[i]);
58
4.81k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
4.81k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
4.81k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
4.81k
        strcpy(es->err_file[i], file);
64
65
4.81k
    es->err_line[i] = line;
66
4.81k
    OPENSSL_free(es->err_func[i]);
67
4.81k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
4.81k
    else
70
4.81k
        es->err_func[i] = OPENSSL_strdup(fn);
71
4.81k
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
52
4.81k
{
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
4.81k
    OPENSSL_free(es->err_file[i]);
58
4.81k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
4.81k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
4.81k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
4.81k
        strcpy(es->err_file[i], file);
64
65
4.81k
    es->err_line[i] = line;
66
4.81k
    OPENSSL_free(es->err_func[i]);
67
4.81k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
4.81k
    else
70
4.81k
        es->err_func[i] = OPENSSL_strdup(fn);
71
4.81k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_prn.c:err_set_debug
72
73
static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
74
                                     void *data, size_t datasz, int flags)
75
2.04k
{
76
2.04k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
77
2.03k
        OPENSSL_free(es->err_data[i]);
78
2.04k
    es->err_data[i] = data;
79
2.04k
    es->err_data_size[i] = datasz;
80
2.04k
    es->err_data_flags[i] = flags;
81
2.04k
}
err.c:err_set_data
Line
Count
Source
75
2.04k
{
76
2.04k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
77
2.03k
        OPENSSL_free(es->err_data[i]);
78
2.04k
    es->err_data[i] = data;
79
2.04k
    es->err_data_size[i] = datasz;
80
2.04k
    es->err_data_flags[i] = flags;
81
2.04k
}
err_blocks.c:err_set_data
Line
Count
Source
75
1
{
76
1
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
77
0
        OPENSSL_free(es->err_data[i]);
78
1
    es->err_data[i] = data;
79
1
    es->err_data_size[i] = datasz;
80
1
    es->err_data_flags[i] = flags;
81
1
}
Unexecuted instantiation: err_mark.c:err_set_data
Unexecuted instantiation: err_prn.c:err_set_data
82
83
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
84
4.83k
{
85
4.83k
    err_clear_data(es, i, (deall));
86
4.83k
    es->err_marks[i] = 0;
87
4.83k
    es->err_flags[i] = 0;
88
4.83k
    es->err_buffer[i] = 0;
89
4.83k
    es->err_line[i] = -1;
90
4.83k
    OPENSSL_free(es->err_file[i]);
91
4.83k
    es->err_file[i] = NULL;
92
4.83k
    OPENSSL_free(es->err_func[i]);
93
4.83k
    es->err_func[i] = NULL;
94
4.83k
}
err.c:err_clear
Line
Count
Source
84
16
{
85
16
    err_clear_data(es, i, (deall));
86
16
    es->err_marks[i] = 0;
87
16
    es->err_flags[i] = 0;
88
16
    es->err_buffer[i] = 0;
89
16
    es->err_line[i] = -1;
90
16
    OPENSSL_free(es->err_file[i]);
91
16
    es->err_file[i] = NULL;
92
16
    OPENSSL_free(es->err_func[i]);
93
16
    es->err_func[i] = NULL;
94
16
}
err_blocks.c:err_clear
Line
Count
Source
84
4.81k
{
85
4.81k
    err_clear_data(es, i, (deall));
86
4.81k
    es->err_marks[i] = 0;
87
4.81k
    es->err_flags[i] = 0;
88
4.81k
    es->err_buffer[i] = 0;
89
4.81k
    es->err_line[i] = -1;
90
4.81k
    OPENSSL_free(es->err_file[i]);
91
4.81k
    es->err_file[i] = NULL;
92
4.81k
    OPENSSL_free(es->err_func[i]);
93
4.81k
    es->err_func[i] = NULL;
94
4.81k
}
err_mark.c:err_clear
Line
Count
Source
84
3
{
85
3
    err_clear_data(es, i, (deall));
86
3
    es->err_marks[i] = 0;
87
3
    es->err_flags[i] = 0;
88
3
    es->err_buffer[i] = 0;
89
3
    es->err_line[i] = -1;
90
3
    OPENSSL_free(es->err_file[i]);
91
3
    es->err_file[i] = NULL;
92
3
    OPENSSL_free(es->err_func[i]);
93
3
    es->err_func[i] = NULL;
94
3
}
Unexecuted instantiation: err_prn.c:err_clear
95
96
ERR_STATE *ossl_err_get_state_int(void);
97
void ossl_err_string_int(unsigned long e, const char *func,
98
                         char *buf, size_t len);