Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76ff250

Browse files
committed
C++: Don't repeat work in BrokenCryptoAlgorithm.ql
The main source of slowness in `BrokenCryptoAlgorithm.ql` was that the regexp on function (macro) names was evaluated once per call (invocation) instead of once per name. Factoring out separate predicates for the problematic functions (macros) fixes this. On https://github.com/ericniebler/range-v3, this change reduces the run time of the two slowest predicates from BrokenCryptoAlgorithm::InsecureMacroSpec#class#f .... 35.1s BrokenCryptoAlgorithm::InsecureFunctionCall#class#f . 12.8s to BrokenCryptoAlgorithm::getAnInsecureFunction#f . 1.2s BrokenCryptoAlgorithm::getAnInsecureMacro#f .... 12ms
1 parent f72ff37 commit 76ff250

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ abstract class InsecureCryptoSpec extends Locatable {
1616
abstract string description();
1717
}
1818

19+
Function getAnInsecureFunction() {
20+
result.getName().regexpMatch(algorithmBlacklistRegex()) and
21+
exists(result.getACallToThisFunction())
22+
}
23+
1924
class InsecureFunctionCall extends InsecureCryptoSpec, FunctionCall {
2025
InsecureFunctionCall() {
21-
this.getTarget().getName().regexpMatch(algorithmBlacklistRegex())
26+
this.getTarget() = getAnInsecureFunction()
2227
}
2328

2429
override string description() { result = "function call" }
@@ -27,9 +32,14 @@ class InsecureFunctionCall extends InsecureCryptoSpec, FunctionCall {
2732
override Location getLocation() { result = FunctionCall.super.getLocation() }
2833
}
2934

35+
Macro getAnInsecureMacro() {
36+
result.getName().regexpMatch(algorithmBlacklistRegex()) and
37+
exists(result.getAnInvocation())
38+
}
39+
3040
class InsecureMacroSpec extends InsecureCryptoSpec, MacroInvocation {
3141
InsecureMacroSpec() {
32-
this.getMacro().getName().regexpMatch(algorithmBlacklistRegex())
42+
this.getMacro() = getAnInsecureMacro()
3343
}
3444

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

0 commit comments

Comments
 (0)