Coverage Report

Created: 2025-12-10 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/err/err_local.h
Line
Count
Source
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.10k
{
16
1.10k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
1.10k
    if (es->top == es->bottom)
18
1.06k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
1.10k
}
Unexecuted instantiation: err.c:err_get_slot
Unexecuted instantiation: err_save.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
1.10k
{
16
1.10k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
1.10k
    if (es->top == es->bottom)
18
1.06k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
1.10k
}
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
2.25k
{
23
2.25k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1.10k
        if (deall) {
25
33
            OPENSSL_free(es->err_data[i]);
26
33
            es->err_data[i] = NULL;
27
33
            es->err_data_size[i] = 0;
28
33
            es->err_data_flags[i] = 0;
29
1.06k
        } else if (es->err_data[i] != NULL) {
30
1.06k
            es->err_data[i][0] = '\0';
31
1.06k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1.06k
        }
33
1.15k
    } else {
34
1.15k
        es->err_data[i] = NULL;
35
1.15k
        es->err_data_size[i] = 0;
36
1.15k
        es->err_data_flags[i] = 0;
37
1.15k
    }
38
2.25k
}
err.c:err_clear_data
Line
Count
Source
22
48
{
23
48
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
33
        if (deall) {
25
33
            OPENSSL_free(es->err_data[i]);
26
33
            es->err_data[i] = NULL;
27
33
            es->err_data_size[i] = 0;
28
33
            es->err_data_flags[i] = 0;
29
33
        } else if (es->err_data[i] != NULL) {
30
0
            es->err_data[i][0] = '\0';
31
0
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
0
        }
33
33
    } else {
34
        es->err_data[i] = NULL;
35
15
        es->err_data_size[i] = 0;
36
15
        es->err_data_flags[i] = 0;
37
15
    }
38
48
}
Unexecuted instantiation: err_save.c:err_clear_data
err_blocks.c:err_clear_data
Line
Count
Source
22
2.20k
{
23
2.20k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1.06k
        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.06k
        } else if (es->err_data[i] != NULL) {
30
1.06k
            es->err_data[i][0] = '\0';
31
1.06k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1.06k
        }
33
1.13k
    } else {
34
        es->err_data[i] = NULL;
35
1.13k
        es->err_data_size[i] = 0;
36
1.13k
        es->err_data_flags[i] = 0;
37
1.13k
    }
38
2.20k
}
err_mark.c:err_clear_data
Line
Count
Source
22
3
{
23
3
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1
        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
        } else if (es->err_data[i] != NULL) {
30
1
            es->err_data[i][0] = '\0';
31
1
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1
        }
33
2
    } else {
34
        es->err_data[i] = NULL;
35
2
        es->err_data_size[i] = 0;
36
2
        es->err_data_flags[i] = 0;
37
2
    }
38
3
}
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.10k
{
43
1.10k
    es->err_buffer[i] = lib == ERR_LIB_SYS
44
1.10k
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
45
1.10k
        : ERR_PACK(lib, 0, reason);
46
1.10k
}
Unexecuted instantiation: err.c:err_set_error
Unexecuted instantiation: err_save.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
1.10k
{
43
1.10k
    es->err_buffer[i] = lib == ERR_LIB_SYS
44
1.10k
        ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
45
1.10k
        : ERR_PACK(lib, 0, reason);
46
1.10k
}
Unexecuted instantiation: err_mark.c:err_set_error
Unexecuted instantiation: err_prn.c:err_set_error
47
48
static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
49
    const char *file, int line,
50
    const char *fn)
51
1.10k
{
52
    /*
53
     * We dup the file and fn strings because they may be provider owned. If the
54
     * provider gets unloaded, they may not be valid anymore.
55
     */
56
1.10k
    OPENSSL_free(es->err_file[i]);
57
1.10k
    if (file == NULL || file[0] == '\0')
58
0
        es->err_file[i] = NULL;
59
1.10k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
60
1.10k
                  NULL, 0))
61
1.10k
        != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
1.10k
        strcpy(es->err_file[i], file);
64
65
1.10k
    es->err_line[i] = line;
66
1.10k
    OPENSSL_free(es->err_func[i]);
67
1.10k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
1.10k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
1.10k
                  NULL, 0))
71
1.10k
        != NULL)
72
1.10k
        strcpy(es->err_func[i], fn);
73
1.10k
}
Unexecuted instantiation: err.c:err_set_debug
Unexecuted instantiation: err_save.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
51
1.10k
{
52
    /*
53
     * We dup the file and fn strings because they may be provider owned. If the
54
     * provider gets unloaded, they may not be valid anymore.
55
     */
56
1.10k
    OPENSSL_free(es->err_file[i]);
57
1.10k
    if (file == NULL || file[0] == '\0')
58
0
        es->err_file[i] = NULL;
59
1.10k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
60
1.10k
                  NULL, 0))
61
1.10k
        != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
1.10k
        strcpy(es->err_file[i], file);
64
65
1.10k
    es->err_line[i] = line;
66
1.10k
    OPENSSL_free(es->err_func[i]);
67
1.10k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
1.10k
    else if ((es->err_func[i] = CRYPTO_malloc(strlen(fn) + 1,
70
1.10k
                  NULL, 0))
71
1.10k
        != NULL)
72
1.10k
        strcpy(es->err_func[i], fn);
73
1.10k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_prn.c:err_set_debug
74
75
static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
76
    void *data, size_t datasz, int flags)
77
1.09k
{
78
1.09k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
79
0
        OPENSSL_free(es->err_data[i]);
80
1.09k
    es->err_data[i] = data;
81
1.09k
    es->err_data_size[i] = datasz;
82
1.09k
    es->err_data_flags[i] = flags;
83
1.09k
}
Unexecuted instantiation: err.c:err_set_data
Unexecuted instantiation: err_save.c:err_set_data
err_blocks.c:err_set_data
Line
Count
Source
77
1.09k
{
78
1.09k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
79
0
        OPENSSL_free(es->err_data[i]);
80
1.09k
    es->err_data[i] = data;
81
1.09k
    es->err_data_size[i] = datasz;
82
1.09k
    es->err_data_flags[i] = flags;
83
1.09k
}
Unexecuted instantiation: err_mark.c:err_set_data
Unexecuted instantiation: err_prn.c:err_set_data
84
85
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
86
1.15k
{
87
1.15k
    err_clear_data(es, i, (deall));
88
1.15k
    es->err_marks[i] = 0;
89
1.15k
    es->err_flags[i] = 0;
90
1.15k
    es->err_buffer[i] = 0;
91
1.15k
    es->err_line[i] = -1;
92
1.15k
    OPENSSL_free(es->err_file[i]);
93
1.15k
    es->err_file[i] = NULL;
94
1.15k
    OPENSSL_free(es->err_func[i]);
95
    es->err_func[i] = NULL;
96
1.15k
}
err.c:err_clear
Line
Count
Source
86
48
{
87
48
    err_clear_data(es, i, (deall));
88
48
    es->err_marks[i] = 0;
89
48
    es->err_flags[i] = 0;
90
48
    es->err_buffer[i] = 0;
91
48
    es->err_line[i] = -1;
92
48
    OPENSSL_free(es->err_file[i]);
93
48
    es->err_file[i] = NULL;
94
48
    OPENSSL_free(es->err_func[i]);
95
    es->err_func[i] = NULL;
96
48
}
Unexecuted instantiation: err_save.c:err_clear
err_blocks.c:err_clear
Line
Count
Source
86
1.10k
{
87
1.10k
    err_clear_data(es, i, (deall));
88
1.10k
    es->err_marks[i] = 0;
89
1.10k
    es->err_flags[i] = 0;
90
1.10k
    es->err_buffer[i] = 0;
91
1.10k
    es->err_line[i] = -1;
92
1.10k
    OPENSSL_free(es->err_file[i]);
93
1.10k
    es->err_file[i] = NULL;
94
1.10k
    OPENSSL_free(es->err_func[i]);
95
    es->err_func[i] = NULL;
96
1.10k
}
err_mark.c:err_clear
Line
Count
Source
86
3
{
87
3
    err_clear_data(es, i, (deall));
88
3
    es->err_marks[i] = 0;
89
3
    es->err_flags[i] = 0;
90
3
    es->err_buffer[i] = 0;
91
3
    es->err_line[i] = -1;
92
3
    OPENSSL_free(es->err_file[i]);
93
3
    es->err_file[i] = NULL;
94
3
    OPENSSL_free(es->err_func[i]);
95
    es->err_func[i] = NULL;
96
3
}
Unexecuted instantiation: err_prn.c:err_clear
97
98
ERR_STATE *ossl_err_get_state_int(void);
99
void ossl_err_string_int(unsigned long e, const char *func,
100
    char *buf, size_t len);