Coverage Report

Created: 2023-06-08 06:40

/src/openssl/crypto/err/err_local.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2021 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
480k
{
16
480k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
480k
    if (es->top == es->bottom)
18
197k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
480k
}
Unexecuted instantiation: err.c:err_get_slot
err_blocks.c:err_get_slot
Line
Count
Source
15
480k
{
16
480k
    es->top = (es->top + 1) % ERR_NUM_ERRORS;
17
480k
    if (es->top == es->bottom)
18
197k
        es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
19
480k
}
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.46M
{
23
1.46M
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
1.43M
        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
1.43M
        } else if (es->err_data[i] != NULL) {
30
1.43M
            es->err_data[i][0] = '\0';
31
1.43M
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
1.43M
        }
33
1.43M
    } else {
34
29.0k
        es->err_data[i] = NULL;
35
29.0k
        es->err_data_size[i] = 0;
36
29.0k
        es->err_data_flags[i] = 0;
37
29.0k
    }
38
1.46M
}
err.c:err_clear_data
Line
Count
Source
22
255k
{
23
255k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
233k
        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
233k
        } else if (es->err_data[i] != NULL) {
30
233k
            es->err_data[i][0] = '\0';
31
233k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
233k
        }
33
233k
    } else {
34
21.9k
        es->err_data[i] = NULL;
35
21.9k
        es->err_data_size[i] = 0;
36
21.9k
        es->err_data_flags[i] = 0;
37
21.9k
    }
38
255k
}
err_blocks.c:err_clear_data
Line
Count
Source
22
960k
{
23
960k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
953k
        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
953k
        } else if (es->err_data[i] != NULL) {
30
953k
            es->err_data[i][0] = '\0';
31
953k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
953k
        }
33
953k
    } else {
34
7.03k
        es->err_data[i] = NULL;
35
7.03k
        es->err_data_size[i] = 0;
36
7.03k
        es->err_data_flags[i] = 0;
37
7.03k
    }
38
960k
}
err_mark.c:err_clear_data
Line
Count
Source
22
249k
{
23
249k
    if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
24
248k
        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
248k
        } else if (es->err_data[i] != NULL) {
30
248k
            es->err_data[i][0] = '\0';
31
248k
            es->err_data_flags[i] = ERR_TXT_MALLOCED;
32
248k
        }
33
248k
    } else {
34
82
        es->err_data[i] = NULL;
35
82
        es->err_data_size[i] = 0;
36
82
        es->err_data_flags[i] = 0;
37
82
    }
38
249k
}
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
480k
{
43
480k
    es->err_buffer[i] =
44
480k
        lib == ERR_LIB_SYS
45
480k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
480k
        : ERR_PACK(lib, 0, reason);
47
480k
}
Unexecuted instantiation: err.c:err_set_error
err_blocks.c:err_set_error
Line
Count
Source
42
480k
{
43
480k
    es->err_buffer[i] =
44
480k
        lib == ERR_LIB_SYS
45
480k
        ? (unsigned int)(ERR_SYSTEM_FLAG |  reason)
46
480k
        : ERR_PACK(lib, 0, reason);
47
480k
}
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
480k
{
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
480k
    OPENSSL_free(es->err_file[i]);
58
480k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
480k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
480k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
480k
        strcpy(es->err_file[i], file);
64
65
480k
    es->err_line[i] = line;
66
480k
    OPENSSL_free(es->err_func[i]);
67
480k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
480k
    else
70
480k
        es->err_func[i] = OPENSSL_strdup(fn);
71
480k
}
Unexecuted instantiation: err.c:err_set_debug
err_blocks.c:err_set_debug
Line
Count
Source
52
480k
{
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
480k
    OPENSSL_free(es->err_file[i]);
58
480k
    if (file == NULL || file[0] == '\0')
59
0
        es->err_file[i] = NULL;
60
480k
    else if ((es->err_file[i] = CRYPTO_malloc(strlen(file) + 1,
61
480k
                                              NULL, 0)) != NULL)
62
        /* We cannot use OPENSSL_strdup due to possible recursion */
63
480k
        strcpy(es->err_file[i], file);
64
65
480k
    es->err_line[i] = line;
66
480k
    OPENSSL_free(es->err_func[i]);
67
480k
    if (fn == NULL || fn[0] == '\0')
68
0
        es->err_func[i] = NULL;
69
480k
    else
70
480k
        es->err_func[i] = OPENSSL_strdup(fn);
71
480k
}
Unexecuted instantiation: err_mark.c:err_set_debug
Unexecuted instantiation: err_prn.c:err_set_debug
72
73
static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
74
                                     void *data, size_t datasz, int flags)
75
97.5k
{
76
97.5k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
77
90.7k
        OPENSSL_free(es->err_data[i]);
78
97.5k
    es->err_data[i] = data;
79
97.5k
    es->err_data_size[i] = datasz;
80
97.5k
    es->err_data_flags[i] = flags;
81
97.5k
}
err.c:err_set_data
Line
Count
Source
75
90.7k
{
76
90.7k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
77
90.7k
        OPENSSL_free(es->err_data[i]);
78
90.7k
    es->err_data[i] = data;
79
90.7k
    es->err_data_size[i] = datasz;
80
90.7k
    es->err_data_flags[i] = flags;
81
90.7k
}
err_blocks.c:err_set_data
Line
Count
Source
75
6.81k
{
76
6.81k
    if ((es->err_data_flags[i] & ERR_TXT_MALLOCED) != 0)
77
0
        OPENSSL_free(es->err_data[i]);
78
6.81k
    es->err_data[i] = data;
79
6.81k
    es->err_data_size[i] = datasz;
80
6.81k
    es->err_data_flags[i] = flags;
81
6.81k
}
Unexecuted instantiation: err_mark.c:err_set_data
Unexecuted instantiation: err_prn.c:err_set_data
82
83
static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
84
894k
{
85
894k
    err_clear_data(es, i, (deall));
86
894k
    es->err_marks[i] = 0;
87
894k
    es->err_flags[i] = 0;
88
894k
    es->err_buffer[i] = 0;
89
894k
    es->err_line[i] = -1;
90
894k
    OPENSSL_free(es->err_file[i]);
91
894k
    es->err_file[i] = NULL;
92
894k
    OPENSSL_free(es->err_func[i]);
93
894k
    es->err_func[i] = NULL;
94
894k
}
err.c:err_clear
Line
Count
Source
84
165k
{
85
165k
    err_clear_data(es, i, (deall));
86
165k
    es->err_marks[i] = 0;
87
165k
    es->err_flags[i] = 0;
88
165k
    es->err_buffer[i] = 0;
89
165k
    es->err_line[i] = -1;
90
165k
    OPENSSL_free(es->err_file[i]);
91
165k
    es->err_file[i] = NULL;
92
165k
    OPENSSL_free(es->err_func[i]);
93
165k
    es->err_func[i] = NULL;
94
165k
}
err_blocks.c:err_clear
Line
Count
Source
84
480k
{
85
480k
    err_clear_data(es, i, (deall));
86
480k
    es->err_marks[i] = 0;
87
480k
    es->err_flags[i] = 0;
88
480k
    es->err_buffer[i] = 0;
89
480k
    es->err_line[i] = -1;
90
480k
    OPENSSL_free(es->err_file[i]);
91
480k
    es->err_file[i] = NULL;
92
480k
    OPENSSL_free(es->err_func[i]);
93
480k
    es->err_func[i] = NULL;
94
480k
}
err_mark.c:err_clear
Line
Count
Source
84
249k
{
85
249k
    err_clear_data(es, i, (deall));
86
249k
    es->err_marks[i] = 0;
87
249k
    es->err_flags[i] = 0;
88
249k
    es->err_buffer[i] = 0;
89
249k
    es->err_line[i] = -1;
90
249k
    OPENSSL_free(es->err_file[i]);
91
249k
    es->err_file[i] = NULL;
92
249k
    OPENSSL_free(es->err_func[i]);
93
249k
    es->err_func[i] = NULL;
94
249k
}
Unexecuted instantiation: err_prn.c:err_clear
95
96
ERR_STATE *ossl_err_get_state_int(void);
97
void ossl_err_string_int(unsigned long e, const char *func,
98
                         char *buf, size_t len);