Skip to content

Commit 005dfdf

Browse files
committed
C++: Speed up cpp/cleartext-transmission ('Encrypted' class).
1 parent 55e69d4 commit 005dfdf

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ class NetworkRecv extends NetworkSendRecv {
168168
override Recv target;
169169
}
170170

171+
predicate encryptionFunction(Function f)
172+
{
173+
f.getName()
174+
.toLowerCase()
175+
.regexpMatch(".*(crypt|encode|decode|hash|securezero).*")
176+
}
177+
178+
predicate encryptionType(Type t)
179+
{
180+
t.getName().toLowerCase().regexpMatch(".*(crypt|encode|decode|hash|securezero).*")
181+
}
182+
171183
/**
172184
* An expression that is an argument or return value from an encryption /
173185
* decryption call. This is quite inclusive to minimize false positives, for
@@ -177,10 +189,7 @@ class NetworkRecv extends NetworkSendRecv {
177189
class Encrypted extends Expr {
178190
Encrypted() {
179191
exists(FunctionCall fc |
180-
fc.getTarget()
181-
.getName()
182-
.toLowerCase()
183-
.regexpMatch(".*(crypt|encode|decode|hash|securezero).*") and
192+
encryptionFunction(fc.getTarget()) and
184193
(
185194
this = fc or
186195
this = fc.getAnArgument()
@@ -189,7 +198,7 @@ class Encrypted extends Expr {
189198
or
190199
exists(Type t |
191200
this.getType().refersTo(t) and
192-
t.getName().toLowerCase().regexpMatch(".*(crypt|encode|decode|hash|securezero).*")
201+
encryptionType(t)
193202
)
194203
}
195204
}

0 commit comments

Comments
 (0)