-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest.cpp
More file actions
149 lines (115 loc) · 2.45 KB
/
test.cpp
File metadata and controls
149 lines (115 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
struct SSL {
// ...
};
int SSL_get_verify_result(const SSL *ssl);
int get_verify_result_indirect(const SSL *ssl) { return SSL_get_verify_result(ssl); }
int something_else(const SSL *ssl);
bool is_ok(int result)
{
return (result == 0); // GOOD
}
bool is_maybe_ok(int result)
{
return (result == 0) || (result == 1); // BAD (conflates OK and a non-OK codes)
}
void test1_1(SSL *ssl)
{
{
int result = SSL_get_verify_result(ssl);
if (result == 0) // GOOD
{
}
if (result == 1) // GOOD
{
}
}
{
int result = SSL_get_verify_result(ssl);
if ((result == 0) || (result == 1)) // BAD (conflates OK and a non-OK codes)
{
}
}
{
int result = SSL_get_verify_result(ssl);
if ((result == 1) || (result == 2)) // GOOD (both results are non-OK)
{
}
}
{
int result = SSL_get_verify_result(ssl);
if ((result == 0) || (false) || (result == 2)) // BAD (conflates OK and a non-OK codes)
{
}
}
{
int result = SSL_get_verify_result(ssl);
if ((0 == result) || (1 == result)) // BAD (conflates OK and a non-OK codes)
{
}
}
{
int result = SSL_get_verify_result(ssl);
if ((result != 0) && (result != 1)) // BAD (conflates OK and a non-OK codes)
{
} else {
// conflation occurs here
}
}
{
int result = SSL_get_verify_result(ssl);
int result_cpy = result;
int result2 = get_verify_result_indirect(ssl);
int result3 = something_else(ssl);
if ((result == 0) || (result_cpy == 1)) // BAD (conflates OK and a non-OK codes)
{
}
if ((result2 == 0) || (result2 == 1)) // BAD (conflates OK and a non-OK codes)
{
}
if ((result3 == 0) || (result3 == 1)) // GOOD (not an SSL result)
{
}
}
if (is_ok(SSL_get_verify_result(ssl)))
{
}
if (is_maybe_ok(SSL_get_verify_result(ssl)))
{
}
{
int result = SSL_get_verify_result(ssl);
bool ok = (result == 0) || (result == 1); // BAD (conflates OK and a non-OK codes)
if (ok) {
}
}
{
int result = SSL_get_verify_result(ssl);
if (result == 1) // BAD (conflates OK and a non-OK codes in `else`) [NOT DETECTED]
{
} else {
}
}
}
void do_good();
void test1_2(SSL *ssl)
{
int result = SSL_get_verify_result(ssl);
if (result == 0) { // GOOD
do_good();
} else if (result == 1) {
throw 1;
} else {
throw 1;
}
}
void test1_3(SSL *ssl)
{
int result = SSL_get_verify_result(ssl);
if (result == 0) { // BAD (error code 1 is treated as OK, not as non-OK) [NOT DETECTED]
do_good();
} else if (result == 1) {
do_good();
} else {
throw 1;
}
}