Skip to content

Commit 0b98397

Browse files
committed
C++: Catch another encryption clue.
1 parent 97447d0 commit 0b98397

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ class Encrypted extends Expr {
171171
this = fc.getAnArgument()
172172
)
173173
)
174+
or
175+
exists(Type t |
176+
this.getType().refersTo(t) and
177+
t.getName().toLowerCase().regexpMatch(".*(crypt|encode|decode|hash|securezero).*")
178+
)
174179
}
175180
}
176181

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/CleartextTransmission.expected

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ edges
8787
| test3.cpp:366:8:366:15 | password | test3.cpp:374:20:374:27 | password |
8888
| test3.cpp:386:8:386:15 | password | test3.cpp:388:15:388:22 | password |
8989
| test3.cpp:398:18:398:25 | password | test3.cpp:400:15:400:23 | & ... |
90+
| test3.cpp:398:18:398:25 | password | test3.cpp:400:16:400:23 | password |
91+
| test3.cpp:398:18:398:25 | password | test3.cpp:400:33:400:40 | password |
9092
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
9193
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
9294
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
@@ -204,6 +206,8 @@ nodes
204206
| test3.cpp:388:15:388:22 | password | semmle.label | password |
205207
| test3.cpp:398:18:398:25 | password | semmle.label | password |
206208
| test3.cpp:400:15:400:23 | & ... | semmle.label | & ... |
209+
| test3.cpp:400:16:400:23 | password | semmle.label | password |
210+
| test3.cpp:400:33:400:40 | password | semmle.label | password |
207211
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
208212
| test.cpp:48:21:48:27 | call to encrypt | semmle.label | call to encrypt |
209213
| test.cpp:48:29:48:39 | thePassword | semmle.label | thePassword |
@@ -234,4 +238,3 @@ subpaths
234238
| test3.cpp:300:2:300:5 | call to send | test3.cpp:308:58:308:66 | password2 | test3.cpp:300:14:300:17 | data | This operation transmits 'data', which may contain unencrypted sensitive data from $@ | test3.cpp:308:58:308:66 | password2 | password2 |
235239
| test3.cpp:341:4:341:7 | call to recv | test3.cpp:339:9:339:16 | password | test3.cpp:341:16:341:23 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:339:9:339:16 | password | password |
236240
| test3.cpp:388:3:388:6 | call to recv | test3.cpp:386:8:386:15 | password | test3.cpp:388:15:388:22 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:386:8:386:15 | password | password |
237-
| test3.cpp:400:3:400:6 | call to recv | test3.cpp:398:18:398:25 | password | test3.cpp:400:15:400:23 | & ... | This operation receives into '& ...', which may put unencrypted sensitive data into $@ | test3.cpp:398:18:398:25 | password | password |

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/test3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void test_more_clues()
397397
{
398398
encrypted_data password;
399399

400-
recv(val(), &password, sizeof(password), val()); // GOOD: password is (probably) encrypted [FALSE POSITIVE]
400+
recv(val(), &password, sizeof(password), val()); // GOOD: password is (probably) encrypted
401401
}
402402
}
403403

0 commit comments

Comments
 (0)