Skip to content

Commit c7382ee

Browse files
committed
C++: Repair for function call macros.
1 parent 012840e commit c7382ee

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ class InsecureFunctionCall extends FunctionCall {
7979
explain = "function call"
8080
or
8181
exists(MacroInvocation mi |
82-
mi.getAnExpandedElement() = this.getAnArgument() and
82+
(
83+
mi.getAnExpandedElement() = this or
84+
mi.getAnExpandedElement() = this.getAnArgument()
85+
) and
8386
mi.getMacro() = getAnInsecureEncryptionMacro() and
8487
blame = mi and
8588
explain = "macro invocation"
@@ -97,7 +100,10 @@ class InsecureFunctionCall extends FunctionCall {
97100
getTarget() = getAdditionalEvidenceFunction()
98101
or
99102
exists(MacroInvocation mi |
100-
mi.getAnExpandedElement() = this.getAnArgument() and
103+
(
104+
mi.getAnExpandedElement() = this or
105+
mi.getAnExpandedElement() = this.getAnArgument()
106+
) and
101107
mi.getMacro() = getAdditionalEvidenceMacro()
102108
)
103109
or

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
@@ -24,3 +24,4 @@
2424
| test.cpp:92:2:92:17 | call to encryptTripleDES | This function call specifies a broken or weak cryptographic algorithm. |
2525
| test.cpp:101:2:101:15 | call to do_des_encrypt | This function call specifies a broken or weak cryptographic algorithm. |
2626
| test.cpp:102:2:102:12 | call to DES_Set_Key | This function call specifies a broken or weak cryptographic algorithm. |
27+
| test.cpp:121:2:121:24 | INIT_ENCRYPT_WITH_DES() | This macro invocation specifies a broken or weak cryptographic algorithm. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void my_implementation8();
118118

119119
void test_macros2()
120120
{
121-
INIT_ENCRYPT_WITH_DES(); // BAD [NOT DETECTED]
121+
INIT_ENCRYPT_WITH_DES(); // BAD
122122
INIT_ENCRYPT_WITH_AES(); // GOOD (good algorithm)
123123

124124
// ...

0 commit comments

Comments
 (0)