Skip to content

Commit 2576075

Browse files
committed
C++: Repair result message.
1 parent 5d1ef49 commit 2576075

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,28 @@ EnumConstant getAdditionalEvidenceEnumConst() {
7070
* encryption algorithm.
7171
*/
7272
class InsecureFunctionCall extends FunctionCall {
73+
Element blame;
74+
string explain;
75+
7376
InsecureFunctionCall() {
7477
// find use of an insecure algorithm name
7578
(
76-
getTarget() = getAnInsecureEncryptionFunction()
79+
getTarget() = getAnInsecureEncryptionFunction() and
80+
blame = this and
81+
explain = "function call"
7782
or
7883
exists(MacroInvocation mi |
7984
mi.getAGeneratedElement() = this.getAChild*() and
80-
mi.getMacro() = getAnInsecureEncryptionMacro()
85+
mi.getMacro() = getAnInsecureEncryptionMacro() and
86+
blame = mi and
87+
explain = "macro invocation"
8188
)
8289
or
8390
exists(EnumConstantAccess ec |
8491
ec = this.getAChild*() and
85-
ec.getTarget() = getAnInsecureEncryptionEnumConst()
92+
ec.getTarget() = getAnInsecureEncryptionEnumConst() and
93+
blame = ec and
94+
explain = "enum constant access"
8695
)
8796
) and
8897
// find additional evidence that this function is related to encryption.
@@ -101,8 +110,14 @@ class InsecureFunctionCall extends FunctionCall {
101110
)
102111
}
103112

104-
string description() { result = "function call" }
113+
Element getBlame() {
114+
result = blame
115+
}
116+
117+
string getDescription() {
118+
result = explain
119+
}
105120
}
106121

107122
from InsecureFunctionCall c
108-
select c, "This " + c.description() + " specifies a broken or weak cryptographic algorithm."
123+
select c.getBlame(), "This " + c.getDescription() + " specifies a broken or weak cryptographic algorithm."

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
| test2.cpp:49:4:49:24 | call to my_des_implementation | This function call specifies a broken or weak cryptographic algorithm. |
2-
| test2.cpp:62:2:62:12 | call to encrypt_bad | This function call specifies a broken or weak cryptographic algorithm. |
2+
| test2.cpp:62:33:62:40 | ALGO_DES | This macro invocation specifies a broken or weak cryptographic algorithm. |
33
| test2.cpp:124:4:124:24 | call to my_des_implementation | This function call specifies a broken or weak cryptographic algorithm. |
4-
| test2.cpp:144:22:144:30 | call to MyBadEncryptor | This function call specifies a broken or weak cryptographic algorithm. |
5-
| test2.cpp:172:2:172:26 | call to set_encryption_algorithm1 | This function call specifies a broken or weak cryptographic algorithm. |
6-
| test2.cpp:175:2:175:26 | call to set_encryption_algorithm2 | This function call specifies a broken or weak cryptographic algorithm. |
7-
| test2.cpp:182:2:182:17 | call to encryption_with1 | This function call specifies a broken or weak cryptographic algorithm. |
8-
| test2.cpp:185:2:185:17 | call to encryption_with2 | This function call specifies a broken or weak cryptographic algorithm. |
9-
| test.cpp:38:2:38:31 | call to my_implementation1 | This function call specifies a broken or weak cryptographic algorithm. |
10-
| test.cpp:39:2:39:31 | call to my_implementation2 | This function call specifies a broken or weak cryptographic algorithm. |
11-
| test.cpp:51:2:51:32 | call to my_implementation1 | This function call specifies a broken or weak cryptographic algorithm. |
12-
| test.cpp:52:2:52:31 | call to my_implementation1 | This function call specifies a broken or weak cryptographic algorithm. |
13-
| test.cpp:53:2:53:25 | call to my_implementation1 | This function call specifies a broken or weak cryptographic algorithm. |
14-
| test.cpp:54:2:54:26 | call to my_implementation1 | This function call specifies a broken or weak cryptographic algorithm. |
4+
| test2.cpp:144:27:144:29 | DES | This enum constant access specifies a broken or weak cryptographic algorithm. |
5+
| test2.cpp:172:28:172:35 | ALGO_DES | This macro invocation specifies a broken or weak cryptographic algorithm. |
6+
| test2.cpp:175:28:175:34 | USE_DES | This enum constant access specifies a broken or weak cryptographic algorithm. |
7+
| test2.cpp:182:38:182:45 | ALGO_DES | This macro invocation specifies a broken or weak cryptographic algorithm. |
8+
| test2.cpp:185:38:185:44 | USE_DES | This enum constant access specifies a broken or weak cryptographic algorithm. |
9+
| test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
10+
| test.cpp:39:2:39:31 | ENCRYPT_WITH_RC2(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
11+
| test.cpp:51:2:51:32 | DES_DO_ENCRYPTION(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
12+
| test.cpp:52:2:52:31 | RUN_DES_ENCODING(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
13+
| test.cpp:53:2:53:25 | DES_ENCODE(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
14+
| test.cpp:54:2:54:26 | DES_SET_KEY(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1515
| test.cpp:88:2:88:11 | call to encryptDES | This function call specifies a broken or weak cryptographic algorithm. |
1616
| test.cpp:89:2:89:11 | call to encryptRC2 | This function call specifies a broken or weak cryptographic algorithm. |
1717
| test.cpp:101:2:101:15 | call to do_des_encrypt | This function call specifies a broken or weak cryptographic algorithm. |

0 commit comments

Comments
 (0)