Coverage Report

Created: 2025-08-28 07:07

/src/openssl34/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
266M
{
16
266M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
266M
    if (es->top == es->bottom)
18
30.7M
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
266M
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
266M
{
16
266M
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
266M
    if (es->top == es->bottom)
18
30.7M
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
266M
}
err_save.c:err_get_slot
Line
Count
Source
15
52.8k
{
16
52.8k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
52.8k
    if (es->top == es->bottom)
18
2.62k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
52.8k
}
Unexecuted instantiation: err_mark.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
1.65G
{
23
1.65G
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
850M
        if (deall) {
25
67.9k
            OPENSSL_free(es->err_data[i]);
26
67.9k
            es->err_data[i] = NULL;
27
67.9k
            es->err_data_size[i] = 0;
28
67.9k
            es->err_data_flags[i] = 0;
29
850M
        } else if (es->err_data[i] != NULL) {
30
850M
            es->err_data[i][0] = '\0';
31
850M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
850M
        }
33
850M
    } else {
34
807M
        es->err_data[i] = NULL;
35
807M
        es->err_data_size[i] = 0;
36
807M
        es->err_data_flags[i] = 0;
37
807M
    }
38
1.65G
}
err.c:err_clear_data
Line
Count
Source
22
919M
{
23
919M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
117M
        if (deall) {
25
67.9k
            OPENSSL_free(es->err_data[i]);
26
67.9k
            es->err_data[i] = NULL;
27
67.9k
            es->err_data_size[i] = 0;
28
67.9k
            es->err_data_flags[i] = 0;
29
117M
        } else if (es->err_data[i] != NULL) {
30
117M
            es->err_data[i][0] = '\0';
31
117M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
117M
        }
33
801M
    } else {
34
801M
        es->err_data[i] = NULL;
35
801M
        es->err_data_size[i] = 0;
36
801M
        es->err_data_flags[i] = 0;
37
801M
    }
38
919M
}
err_blocks.c:err_clear_data
Line
Count
Source
22
533M
{
23
533M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
528M
        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
528M
        } else if (es->err_data[i] != NULL) {
30
528M
            es->err_data[i][0] = '\0';
31
528M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
528M
        }
33
528M
    } else {
34
4.41M
        es->err_data[i] = NULL;
35
4.41M
        es->err_data_size[i] = 0;
36
4.41M
        es->err_data_flags[i] = 0;
37
4.41M
    }
38
533M
}
err_save.c:err_clear_data
Line
Count
Source
22
621k
{
23
621k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
2.12k
        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.12k
        } else if (es->err_data[i] != NULL) {
30
2.12k
            es->err_data[i][0] = '\0';
31
2.12k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
2.12k
        }
33
619k
    } else {
34
619k
        es->err_data[i] = NULL;
35
619k
        es->err_data_size[i] = 0;
36
619k
        es->err_data_flags[i] = 0;
37
619k
    }
38
621k
}
err_mark.c:err_clear_data
Line
Count
Source
22
204M
{
23
204M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
203M
        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
203M
        } else if (es->err_data[i] != NULL) {
30
203M
            es->err_data[i][0] = '\0';
31
203M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
203M
        }
33
203M
    } else {
34
444k
        es->err_data[i] = NULL;
35
444k
        es->err_data_size[i] = 0;
36
444k
        es->err_data_flags[i] = 0;
37
444k
    }
38
204M
}
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
266M
{
43
266M
    es->err_buffer[i] =
44
266M
        lib == ERR_LIB_SYS
45
266M
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
266M
        : ERR_PACK(lib, 0, reason);
47
266M
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
266M
{
43
266M
    es->err_buffer[i] =
44
266M
        lib == ERR_LIB_SYS
45
266M
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
266M
        : ERR_PACK(lib, 0, reason);
47
266M
}
Unexecuted instantiation: err_save.c:err_set_error
Unexecuted instantiation: err_mark.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
231M
{
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
231M
    OPENSSL_free(es->err_file[i]);
58
231M
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
231M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
231M
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
231M
        strcpy(es->err_file[i], file);
64
65
231M
    es->err_line[i] = line;
66
231M
    OPENSSL_free(es->err_func[i]);
67
231M
    if (fn == NULL || fn[0] == '\0')
68
7.43k
        es->err_func[i] = NULL;
69
231M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
231M
                                              NULL, 0)) != NULL)
71
231M
        strcpy(es->err_func[i], fn);
72
231M
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
52
231M
{
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
231M
    OPENSSL_free(es->err_file[i]);
58
231M
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
231M
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
231M
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
231M
        strcpy(es->err_file[i], file);
64
65
231M
    es->err_line[i] = line;
66
231M
    OPENSSL_free(es->err_func[i]);
67
231M
    if (fn == NULL || fn[0] == '\0')
68
7.43k
        es->err_func[i] = NULL;
69
231M
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
231M
                                              NULL, 0)) != NULL)
71
231M
        strcpy(es->err_func[i], fn);
72
231M
}
err_save.c:err_set_debug
Line
Count
Source
52
52.8k
{
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
52.8k
    OPENSSL_free(es->err_file[i]);
58
52.8k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
52.8k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
52.8k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
52.8k
        strcpy(es->err_file[i], file);
64
65
52.8k
    es->err_line[i] = line;
66
52.8k
    OPENSSL_free(es->err_func[i]);
67
52.8k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
52.8k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
52.8k
                                              NULL, 0)) != NULL)
71
52.8k
        strcpy(es->err_func[i], fn);
72
52.8k
}
Unexecuted instantiation: err_mark.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
18.8M
{
77
18.8M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
15.6M
        OPENSSL_free(es->err_data[i]);
79
18.8M
    es->err_data[i] = data;
80
18.8M
    es->err_data_size[i] = datasz;
81
18.8M
    es->err_data_flags[i] = flags;
82
18.8M
}
err.c:err_set_data
Line
Count
Source
76
15.6M
{
77
15.6M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
15.6M
        OPENSSL_free(es->err_data[i]);
79
15.6M
    es->err_data[i] = data;
80
15.6M
    es->err_data_size[i] = datasz;
81
15.6M
    es->err_data_flags[i] = flags;
82
15.6M
}
err_blocks.c:err_set_data
Line
Count
Source
76
3.16M
{
77
3.16M
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
0
        OPENSSL_free(es->err_data[i]);
79
3.16M
    es->err_data[i] = data;
80
3.16M
    es->err_data_size[i] = datasz;
81
3.16M
    es->err_data_flags[i] = flags;
82
3.16M
}
err_save.c:err_set_data
Line
Count
Source
76
44.9k
{
77
44.9k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
78
957
        OPENSSL_free(es->err_data[i]);
79
44.9k
    es->err_data[i] = data;
80
44.9k
    es->err_data_size[i] = datasz;
81
44.9k
    es->err_data_flags[i] = flags;
82
44.9k
}
Unexecuted instantiation: err_mark.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
1.37G
{
86
1.37G
    err_clear_data(es, i, (deall));
87
1.37G
    es->err_marks[i] = 0;
88
1.37G
    es->err_flags[i] = 0;
89
1.37G
    es->err_buffer[i] = 0;
90
1.37G
    es->err_line[i] = -1;
91
1.37G
    OPENSSL_free(es->err_file[i]);
92
1.37G
    es->err_file[i] = NULL;
93
1.37G
    OPENSSL_free(es->err_func[i]);
94
1.37G
    es->err_func[i] = NULL;
95
1.37G
}
err.c:err_clear
Line
Count
Source
85
903M
{
86
903M
    err_clear_data(es, i, (deall));
87
903M
    es->err_marks[i] = 0;
88
903M
    es->err_flags[i] = 0;
89
903M
    es->err_buffer[i] = 0;
90
903M
    es->err_line[i] = -1;
91
903M
    OPENSSL_free(es->err_file[i]);
92
903M
    es->err_file[i] = NULL;
93
903M
    OPENSSL_free(es->err_func[i]);
94
903M
    es->err_func[i] = NULL;
95
903M
}
err_blocks.c:err_clear
Line
Count
Source
85
266M
{
86
266M
    err_clear_data(es, i, (deall));
87
266M
    es->err_marks[i] = 0;
88
266M
    es->err_flags[i] = 0;
89
266M
    es->err_buffer[i] = 0;
90
266M
    es->err_line[i] = -1;
91
266M
    OPENSSL_free(es->err_file[i]);
92
266M
    es->err_file[i] = NULL;
93
266M
    OPENSSL_free(es->err_func[i]);
94
266M
    es->err_func[i] = NULL;
95
266M
}
err_save.c:err_clear
Line
Count
Source
85
613k
{
86
613k
    err_clear_data(es, i, (deall));
87
613k
    es->err_marks[i] = 0;
88
613k
    es->err_flags[i] = 0;
89
613k
    es->err_buffer[i] = 0;
90
613k
    es->err_line[i] = -1;
91
613k
    OPENSSL_free(es->err_file[i]);
92
613k
    es->err_file[i] = NULL;
93
613k
    OPENSSL_free(es->err_func[i]);
94
613k
    es->err_func[i] = NULL;
95
613k
}
err_mark.c:err_clear
Line
Count
Source
85
204M
{
86
204M
    err_clear_data(es, i, (deall));
87
204M
    es->err_marks[i] = 0;
88
204M
    es->err_flags[i] = 0;
89
204M
    es->err_buffer[i] = 0;
90
204M
    es->err_line[i] = -1;
91
204M
    OPENSSL_free(es->err_file[i]);
92
204M
    es->err_file[i] = NULL;
93
204M
    OPENSSL_free(es->err_func[i]);
94
204M
    es->err_func[i] = NULL;
95
204M
}
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);