Coverage Report

Created: 2025-06-13 06:56

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