Coverage Report

Created: 2025-06-13 06:57

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