Skip to content

Commit b5c71fd

Browse files
committed
C++: Repair funcion call in a function call.
1 parent e5147c2 commit b5c71fd

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

cpp/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.ql

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ EnumConstant getAdditionalEvidenceEnumConst() { isEncryptionAdditionalEvidence(r
7070
predicate getInsecureEncryptionEvidence(FunctionCall fc, Element blame, string description) {
7171
// find use of an insecure algorithm name
7272
(
73-
fc.getTarget() = getAnInsecureEncryptionFunction() and
74-
blame = fc and
75-
description = "call to " + fc.getTarget().getName()
73+
exists(FunctionCall fc2 |
74+
fc.getAChild*() = fc2 and
75+
fc2.getTarget() = getAnInsecureEncryptionFunction() and
76+
blame = fc2 and
77+
description = "call to " + fc.getTarget().getName()
78+
)
7679
or
7780
exists(MacroInvocation mi |
7881
(
@@ -93,7 +96,10 @@ predicate getInsecureEncryptionEvidence(FunctionCall fc, Element blame, string d
9396
) and
9497
// find additional evidence that this function is related to encryption.
9598
(
96-
fc.getTarget() = getAnAdditionalEvidenceFunction()
99+
exists(FunctionCall fc2 |
100+
fc.getAChild*() = fc2 and
101+
fc2.getTarget() = getAnAdditionalEvidenceFunction()
102+
)
97103
or
98104
exists(MacroInvocation mi |
99105
(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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:304:20:304:37 | call to desEncryptor | call to desEncryptor |
1111
| 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:308:5:308:19 | call to doDesEncryption | call to doDesEncryption |
1212
| 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:309:9:309:23 | call to doDesEncryption | call to doDesEncryption |
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:403:26:403:45 | call to getEncryptionNameDES | call to doEncryption |
1314
| 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 |
1415
| 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 |
1516
| 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,6 @@ void doEncryption(char *data, size_t len, const char *algorithmName);
400400

401401
void test_fn_in_fn(char *data, size_t len)
402402
{
403-
doEncryption(data, len, getEncryptionNameDES()); // BAD [NOT DETECTED]
403+
doEncryption(data, len, getEncryptionNameDES()); // BAD
404404
doEncryption(data, len, getEncryptionNameAES()); // GOOD
405405
}

0 commit comments

Comments
 (0)