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

Skip to content

Commit 6e6c169

Browse files
committed
CPP: Speed up SensitiveExprs.qll 'suspicious' and 'nonSuspicious' mechanism.
1 parent 18e1708 commit 6e6c169

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import cpp
22

3-
private string suspicious() {
4-
result = "%password%" or
5-
result = "%passwd%" or
6-
result = "%account%" or
7-
result = "%accnt%" or
8-
result = "%trusted%"
9-
}
10-
11-
private string nonSuspicious() {
12-
result = "%hashed%" or
13-
result = "%encrypted%" or
14-
result = "%crypt%"
3+
bindingset[s]
4+
private predicate suspicious(string s) {
5+
(
6+
s.matches("%password%") or
7+
s.matches("%passwd%") or
8+
s.matches("%account%") or
9+
s.matches("%accnt%") or
10+
s.matches("%trusted%")
11+
) and not (
12+
s.matches("%hashed%") or
13+
s.matches("%encrypted%") or
14+
s.matches("%crypt%")
15+
)
1516
}
1617

1718
abstract class SensitiveExpr extends Expr { }
@@ -20,8 +21,7 @@ class SensitiveVarAccess extends SensitiveExpr {
2021
SensitiveVarAccess() {
2122
this instanceof VariableAccess and
2223
exists(string s | this.toString().toLowerCase() = s |
23-
s.matches(suspicious()) and
24-
not s.matches(nonSuspicious())
24+
suspicious(s)
2525
)
2626
}
2727
}
@@ -30,8 +30,7 @@ class SensitiveCall extends SensitiveExpr {
3030
SensitiveCall() {
3131
this instanceof FunctionCall and
3232
exists(string s | this.toString().toLowerCase() = s |
33-
s.matches(suspicious()) and
34-
not s.matches(nonSuspicious())
33+
suspicious(s)
3534
)
3635
}
3736
}

0 commit comments

Comments
 (0)