Coverage Report

Created: 2024-09-08 06:32

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