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