Coverage Report

Created: 2024-11-21 07:03

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