Coverage Report

Created: 2025-07-18 06:46

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