Coverage Report

Created: 2024-07-27 06:35

/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
339k
{
16
339k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
339k
    if (es->top == es->bottom)
18
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
339k
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
339k
{
16
339k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
339k
    if (es->top == es->bottom)
18
0
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
339k
}
Unexecuted instantiation: err_mark.c:err_get_slot
Unexecuted instantiation: err_prn.c:err_get_slot
Unexecuted instantiation: err_save.c:err_get_slot
20
21
static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall)
22
1.42M
{
23
1.42M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1.09M
        if (deall) {
25
10
            OPENSSL_free(es->err_data[i]);
26
10
            es->err_data[i] = NULL;
27
10
            es->err_data_size[i] = 0;
28
10
            es->err_data_flags[i] = 0;
29
1.09M
        } else if (es->err_data[i] != NULL) {
30
1.09M
            es->err_data[i][0] = '\0';
31
1.09M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1.09M
        }
33
1.09M
    } else {
34
330k
        es->err_data[i] = NULL;
35
330k
        es->err_data_size[i] = 0;
36
330k
        es->err_data_flags[i] = 0;
37
330k
    }
38
1.42M
}
err.c:err_clear_data
Line
Count
Source
22
410k
{
23
410k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
153k
        if (deall) {
25
10
            OPENSSL_free(es->err_data[i]);
26
10
            es->err_data[i] = NULL;
27
10
            es->err_data_size[i] = 0;
28
10
            es->err_data_flags[i] = 0;
29
153k
        } else if (es->err_data[i] != NULL) {
30
153k
            es->err_data[i][0] = '\0';
31
153k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
153k
        }
33
256k
    } else {
34
256k
        es->err_data[i] = NULL;
35
256k
        es->err_data_size[i] = 0;
36
256k
        es->err_data_flags[i] = 0;
37
256k
    }
38
410k
}
err_blocks.c:err_clear_data
Line
Count
Source
22
679k
{
23
679k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
606k
        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
606k
        } else if (es->err_data[i] != NULL) {
30
606k
            es->err_data[i][0] = '\0';
31
606k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
606k
        }
33
606k
    } else {
34
73.8k
        es->err_data[i] = NULL;
35
73.8k
        es->err_data_size[i] = 0;
36
73.8k
        es->err_data_flags[i] = 0;
37
73.8k
    }
38
679k
}
err_mark.c:err_clear_data
Line
Count
Source
22
335k
{
23
335k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
335k
        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
335k
        } else if (es->err_data[i] != NULL) {
30
335k
            es->err_data[i][0] = '\0';
31
335k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
335k
        }
33
335k
    } else {
34
55
        es->err_data[i] = NULL;
35
55
        es->err_data_size[i] = 0;
36
55
        es->err_data_flags[i] = 0;
37
55
    }
38
335k
}
Unexecuted instantiation: err_prn.c:err_clear_data
Unexecuted instantiation: err_save.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
339k
{
43
339k
    es->err_buffer[i] =
44
339k
        lib == ERR_LIB_SYS
45
339k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
339k
        : ERR_PACK(lib, 0, reason);
47
339k
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
339k
{
43
339k
    es->err_buffer[i] =
44
339k
        lib == ERR_LIB_SYS
45
339k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
339k
        : ERR_PACK(lib, 0, reason);
47
339k
}
Unexecuted instantiation: err_mark.c:err_set_error
Unexecuted instantiation: err_prn.c:err_set_error
Unexecuted instantiation: err_save.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
339k
{
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
339k
    OPENSSL_free(es->err_file[i]);
58
339k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
339k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
339k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
339k
        strcpy(es->err_file[i], file);
64
65
339k
    es->err_line[i] = line;
66
339k
    OPENSSL_free(es->err_func[i]);
67
339k
    if (fn == NULL || fn[0] == '\0')
68
76
        es->err_func[i] = NULL;
69
339k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
339k
                                              NULL, 0)) != NULL)
71
339k
        strcpy(es->err_func[i], fn);
72
339k
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
52
339k
{
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
339k
    OPENSSL_free(es->err_file[i]);
58
339k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
339k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
339k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
339k
        strcpy(es->err_file[i], file);
64
65
339k
    es->err_line[i] = line;
66
339k
    OPENSSL_free(es->err_func[i]);
67
339k
    if (fn == NULL || fn[0] == '\0')
68
76
        es->err_func[i] = NULL;
69
339k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
339k
                                              NULL, 0)) != NULL)
71
339k
        strcpy(es->err_func[i], fn);
72
339k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_prn.c:err_set_debug
Unexecuted instantiation: err_save.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
73.5k
{
77
73.5k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
260
        OPENSSL_free(es->err_data[i]);
79
73.5k
    es->err_data[i] = data;
80
73.5k
    es->err_data_size[i] = datasz;
81
73.5k
    es->err_data_flags[i] = flags;
82
73.5k
}
err.c:err_set_data
Line
Count
Source
76
268
{
77
268
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
260
        OPENSSL_free(es->err_data[i]);
79
268
    es->err_data[i] = data;
80
268
    es->err_data_size[i] = datasz;
81
268
    es->err_data_flags[i] = flags;
82
268
}
err_blocks.c:err_set_data
Line
Count
Source
76
73.2k
{
77
73.2k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
0
        OPENSSL_free(es->err_data[i]);
79
73.2k
    es->err_data[i] = data;
80
73.2k
    es->err_data_size[i] = datasz;
81
73.2k
    es->err_data_flags[i] = flags;
82
73.2k
}
Unexecuted instantiation: err_mark.c:err_set_data
Unexecuted instantiation: err_prn.c:err_set_data
Unexecuted instantiation: err_save.c:err_set_data
83
84
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
85
1.08M
{
86
1.08M
    err_clear_data(es, i, (deall));
87
1.08M
    es->err_marks[i] = 0;
88
1.08M
    es->err_flags[i] = 0;
89
1.08M
    es->err_buffer[i] = 0;
90
1.08M
    es->err_line[i] = -1;
91
1.08M
    OPENSSL_free(es->err_file[i]);
92
1.08M
    es->err_file[i] = NULL;
93
1.08M
    OPENSSL_free(es->err_func[i]);
94
1.08M
    es->err_func[i] = NULL;
95
1.08M
}
err.c:err_clear
Line
Count
Source
85
409k
{
86
409k
    err_clear_data(es, i, (deall));
87
409k
    es->err_marks[i] = 0;
88
409k
    es->err_flags[i] = 0;
89
409k
    es->err_buffer[i] = 0;
90
409k
    es->err_line[i] = -1;
91
409k
    OPENSSL_free(es->err_file[i]);
92
409k
    es->err_file[i] = NULL;
93
409k
    OPENSSL_free(es->err_func[i]);
94
409k
    es->err_func[i] = NULL;
95
409k
}
err_blocks.c:err_clear
Line
Count
Source
85
339k
{
86
339k
    err_clear_data(es, i, (deall));
87
339k
    es->err_marks[i] = 0;
88
339k
    es->err_flags[i] = 0;
89
339k
    es->err_buffer[i] = 0;
90
339k
    es->err_line[i] = -1;
91
339k
    OPENSSL_free(es->err_file[i]);
92
339k
    es->err_file[i] = NULL;
93
339k
    OPENSSL_free(es->err_func[i]);
94
339k
    es->err_func[i] = NULL;
95
339k
}
err_mark.c:err_clear
Line
Count
Source
85
335k
{
86
335k
    err_clear_data(es, i, (deall));
87
335k
    es->err_marks[i] = 0;
88
335k
    es->err_flags[i] = 0;
89
335k
    es->err_buffer[i] = 0;
90
335k
    es->err_line[i] = -1;
91
335k
    OPENSSL_free(es->err_file[i]);
92
335k
    es->err_file[i] = NULL;
93
335k
    OPENSSL_free(es->err_func[i]);
94
335k
    es->err_func[i] = NULL;
95
335k
}
Unexecuted instantiation: err_prn.c:err_clear
Unexecuted instantiation: err_save.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);