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