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