Skip to content

Commit 0450caa

Browse files
committed
C++: Exclude array initializers.
1 parent 52a88af commit 0450caa

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class InsecureMacroSpec extends InsecureCryptoSpec, MacroInvocation {
4848
exists(this.getAGeneratedElement().(ControlFlowNode)) and
4949
// exclude expressions controlling ifs/switches (as they may not be used).
5050
not any(IfStmt c).getCondition().getAChild*() = this.getAGeneratedElement() and
51-
not any(SwitchCase c).getExpr().getAChild*() = this.getAGeneratedElement()
51+
not any(SwitchCase c).getExpr().getAChild*() = this.getAGeneratedElement() and
52+
// exclude expressions in array initializers (as they may not be used).
53+
not any(AggregateLiteral i).getAChild*() = this.getAGeneratedElement()
5254
}
5355

5456
override string description() { result = "macro invocation" }

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
| test2.cpp:25:2:25:9 | ALGO_DES | This macro invocation specifies a broken or weak cryptographic algorithm. |
21
| test2.cpp:49:4:49:24 | call to my_des_implementation | This function call specifies a broken or weak cryptographic algorithm. |
32
| test2.cpp:62:33:62:40 | ALGO_DES | This macro invocation specifies a broken or weak cryptographic algorithm. |
43
| test2.cpp:124:4:124:24 | call to my_des_implementation | This function call specifies a broken or weak cryptographic algorithm. |

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
@@ -22,7 +22,7 @@ typedef void (*implementation_fn_ptr)(char *data, size_t amount, keytype key);
2222
#define ALGO_AES (2)
2323

2424
int all_algos[] = {
25-
ALGO_DES, // [FALSE POSITIVE]
25+
ALGO_DES,
2626
ALGO_AES
2727
};
2828

0 commit comments

Comments
 (0)