Skip to content

Commit dca397d

Browse files
committed
C++: Add a test case with a template class.
1 parent 96d8fc7 commit dca397d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:185:38:185:44 | USE_DES | access of enum constant USE_DES |
99
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:238:2:238:20 | call to encrypt | call to encrypt |
1010
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:245:5:245:11 | call to encrypt | call to encrypt |
11+
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:279:9:279:15 | call to desEncryptor | call to desEncryptor |
12+
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:300:20:300:37 | call to desEncryptor | call to desEncryptor |
13+
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:304:5:304:19 | call to doDesEncryption | call to doDesEncryption |
14+
| test2.cpp:49:4:49:24 | call to my_des_implementation | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test2.cpp:305:9:305:23 | call to doDesEncryption | call to doDesEncryption |
1115
| test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | invocation of macro ENCRYPT_WITH_DES |
1216
| test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test.cpp:39:2:39:31 | ENCRYPT_WITH_RC2(data,amount) | invocation of macro ENCRYPT_WITH_RC2 |
1317
| test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | This file makes use of a broken or weak cryptographic algorithm (specified by $@). | test.cpp:41:2:41:32 | ENCRYPT_WITH_3DES(data,amount) | invocation of macro ENCRYPT_WITH_3DES |

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,48 @@ void do_fn_ptr(char *data, size_t amount, keytype key)
260260
impl = &my_aes_implementation; // GOOD
261261
impl(data, amount, key);
262262
}
263+
264+
// --- template classes ---
265+
266+
class desEncryptor
267+
{
268+
public:
269+
desEncryptor();
270+
271+
void doDesEncryption(char *data);
272+
};
273+
274+
template <class C>
275+
class container
276+
{
277+
public:
278+
container() {
279+
obj = new C(); // GOOD [FALSE POSITIVE]
280+
}
281+
282+
~container() {
283+
delete obj;
284+
}
285+
286+
C *obj;
287+
};
288+
289+
template <class C>
290+
class templateDesEncryptor
291+
{
292+
public:
293+
templateDesEncryptor();
294+
295+
void doDesEncryption(C &data);
296+
};
297+
298+
void do_template_classes(char *data)
299+
{
300+
desEncryptor *p = new desEncryptor(); // BAD
301+
container<desEncryptor> c; // BAD [NOT DETECTED]
302+
templateDesEncryptor<char *> t; // BAD [NOT DETECTED]
303+
304+
p->doDesEncryption(data); // BAD
305+
c.obj->doDesEncryption(data); // BAD
306+
t.doDesEncryption(data); // BAD [NOT DETECTED]
307+
}

0 commit comments

Comments
 (0)