Coverage Report

Created: 2024-07-27 06:36

/src/openssl/crypto/err/err_mark.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2003-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
#define OSSL_FORCE_ERR_STATE
11
12
#include <openssl/err.h>
13
#include "err_local.h"
14
15
int ERR_set_mark(void)
16
283k
{
17
283k
    ERR_STATE *es;
18
19
283k
    es = ossl_err_get_state_int();
20
283k
    if (es == NULL)
21
0
        return 0;
22
23
283k
    if (es->bottom == es->top)
24
283k
        return 0;
25
0
    es->err_marks[es->top]++;
26
0
    return 1;
27
283k
}
28
29
int ERR_pop(void)
30
0
{
31
0
    ERR_STATE *es;
32
33
0
    es = ossl_err_get_state_int();
34
0
    if (es == NULL || es->bottom == es->top)
35
0
        return 0;
36
37
0
    err_clear(es, es->top, 0);
38
0
    es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
39
0
    return 1;
40
0
}
41
42
int ERR_pop_to_mark(void)
43
279k
{
44
279k
    ERR_STATE *es;
45
46
279k
    es = ossl_err_get_state_int();
47
279k
    if (es == NULL)
48
0
        return 0;
49
50
328k
    while (es->bottom != es->top
51
328k
           && es->err_marks[es->top] == 0) {
52
48.9k
        err_clear(es, es->top, 0);
53
48.9k
        es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
54
48.9k
    }
55
56
279k
    if (es->bottom == es->top)
57
279k
        return 0;
58
0
    es->err_marks[es->top]--;
59
0
    return 1;
60
279k
}
61
62
int ERR_count_to_mark(void)
63
0
{
64
0
    ERR_STATE *es;
65
0
    int count = 0, top;
66
67
0
    es = ossl_err_get_state_int();
68
0
    if (es == NULL)
69
0
        return 0;
70
71
0
    top = es->top;
72
0
    while (es->bottom != top
73
0
           && es->err_marks[top] == 0) {
74
0
        ++count;
75
0
        top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
76
0
    }
77
78
0
    return count;
79
0
}
80
81
int ERR_clear_last_mark(void)
82
4.05k
{
83
4.05k
    ERR_STATE *es;
84
4.05k
    int top;
85
86
4.05k
    es = ossl_err_get_state_int();
87
4.05k
    if (es == NULL)
88
0
        return 0;
89
90
4.05k
    top = es->top;
91
4.05k
    while (es->bottom != top
92
4.05k
           && es->err_marks[top] == 0) {
93
0
        top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
94
0
    }
95
96
4.05k
    if (es->bottom == top)
97
4.05k
        return 0;
98
0
    es->err_marks[top]--;
99
0
    return 1;
100
4.05k
}
101