Skip to content

Commit 012840e

Browse files
committed
C++: Add more test cases.
1 parent 3d8513c commit 012840e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-327/BrokenCryptoAlgorithm.expected

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
| test2.cpp:175:28:175:34 | USE_DES | This enum constant access specifies a broken or weak cryptographic algorithm. |
77
| test2.cpp:182:38:182:45 | ALGO_DES | This macro invocation specifies a broken or weak cryptographic algorithm. |
88
| test2.cpp:185:38:185:44 | USE_DES | This enum constant access specifies a broken or weak cryptographic algorithm. |
9-
| test2.cpp:234:2:234:20 | call to encrypt | This function call specifies a broken or weak cryptographic algorithm. |
10-
| test2.cpp:239:5:239:11 | call to encrypt | This function call specifies a broken or weak cryptographic algorithm. |
9+
| test2.cpp:238:2:238:20 | call to encrypt | This function call specifies a broken or weak cryptographic algorithm. |
10+
| test2.cpp:240:2:240:28 | call to doSomethingElse | This function call specifies a broken or weak cryptographic algorithm. |
11+
| test2.cpp:245:5:245:11 | call to encrypt | This function call specifies a broken or weak cryptographic algorithm. |
12+
| test2.cpp:247:5:247:19 | call to doSomethingElse | This function call specifies a broken or weak cryptographic algorithm. |
1113
| test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1214
| test.cpp:39:2:39:31 | ENCRYPT_WITH_RC2(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1315
| test.cpp:41:2:41:32 | ENCRYPT_WITH_3DES(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |

cpp/ql/test/query-tests/Security/CWE/CWE-327/test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,19 @@ void test_functions(void *data, size_t amount, const char *str)
107107
Anodes(1); // GOOD (probably nothing to do with encryption)
108108
ConDes(); // GOOD (probably nothing to do with encryption)
109109
}
110+
111+
// --- macros for functions with no arguments ---
112+
113+
void my_implementation7();
114+
void my_implementation8();
115+
116+
#define INIT_ENCRYPT_WITH_DES() my_implementation7()
117+
#define INIT_ENCRYPT_WITH_AES() my_implementation8()
118+
119+
void test_macros2()
120+
{
121+
INIT_ENCRYPT_WITH_DES(); // BAD [NOT DETECTED]
122+
INIT_ENCRYPT_WITH_AES(); // GOOD (good algorithm)
123+
124+
// ...
125+
}

cpp/ql/test/query-tests/Security/CWE/CWE-327/test2.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,35 +209,43 @@ class desEncrypt
209209
{
210210
public:
211211
static void encrypt(const char *data);
212+
static void doSomethingElse();
212213
};
213214

214215
class aes256Encrypt
215216
{
216217
public:
217218
static void encrypt(const char *data);
219+
static void doSomethingElse();
218220
};
219221

220222
class desCipher
221223
{
222224
public:
223225
void encrypt(const char *data);
226+
void doSomethingElse();
224227
};
225228

226229
class aesCipher
227230
{
228231
public:
229232
void encrypt(const char *data);
233+
void doSomethingElse();
230234
};
231235

232236
void do_classes(const char *data)
233237
{
234238
desEncrypt::encrypt(data); // BAD
235239
aes256Encrypt::encrypt(data); // GOOD
240+
desEncrypt::doSomethingElse(); // GOOD [FALSE POSITIVE]
241+
aes256Encrypt::doSomethingElse(); // GOOD
236242

237243
desCipher dc;
238244
aesCipher ac;
239245
dc.encrypt(data); // BAD
240246
ac.encrypt(data); // GOOD
247+
dc.doSomethingElse(); // GOOD [FALSE POSITIVE]
248+
ac.doSomethingElse(); // GOOD
241249
}
242250

243251
// --- function pointer ---

0 commit comments

Comments
 (0)