Skip to content

Commit cc20969

Browse files
committed
C++: Add test cases based on some remaining real world FPs.
1 parent 7bb11b8 commit cc20969

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ edges
8989
| test3.cpp:398:18:398:25 | password | test3.cpp:400:15:400:23 | & ... |
9090
| test3.cpp:398:18:398:25 | password | test3.cpp:400:16:400:23 | password |
9191
| test3.cpp:398:18:398:25 | password | test3.cpp:400:33:400:40 | password |
92+
| test3.cpp:429:7:429:14 | password | test3.cpp:431:8:431:15 | password |
93+
| test3.cpp:436:7:436:14 | password | test3.cpp:439:8:439:15 | password |
94+
| test3.cpp:436:7:436:14 | password | test3.cpp:440:8:440:15 | password |
95+
| test3.cpp:448:7:448:14 | password | test3.cpp:452:10:452:17 | password |
9296
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
9397
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
9498
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
@@ -208,6 +212,13 @@ nodes
208212
| test3.cpp:400:15:400:23 | & ... | semmle.label | & ... |
209213
| test3.cpp:400:16:400:23 | password | semmle.label | password |
210214
| test3.cpp:400:33:400:40 | password | semmle.label | password |
215+
| test3.cpp:429:7:429:14 | password | semmle.label | password |
216+
| test3.cpp:431:8:431:15 | password | semmle.label | password |
217+
| test3.cpp:436:7:436:14 | password | semmle.label | password |
218+
| test3.cpp:439:8:439:15 | password | semmle.label | password |
219+
| test3.cpp:440:8:440:15 | password | semmle.label | password |
220+
| test3.cpp:448:7:448:14 | password | semmle.label | password |
221+
| test3.cpp:452:10:452:17 | password | semmle.label | password |
211222
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
212223
| test.cpp:48:21:48:27 | call to encrypt | semmle.label | call to encrypt |
213224
| test.cpp:48:29:48:39 | thePassword | semmle.label | thePassword |
@@ -238,3 +249,7 @@ subpaths
238249
| 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 |
239250
| 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 |
240251
| 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 |
252+
| test3.cpp:431:2:431:6 | call to fgets | test3.cpp:429:7:429:14 | password | test3.cpp:431:8:431:15 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:429:7:429:14 | password | password |
253+
| test3.cpp:439:2:439:6 | call to fgets | test3.cpp:436:7:436:14 | password | test3.cpp:439:8:439:15 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:436:7:436:14 | password | password |
254+
| test3.cpp:440:2:440:6 | call to fgets | test3.cpp:436:7:436:14 | password | test3.cpp:440:8:440:15 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:436:7:436:14 | password | password |
255+
| test3.cpp:452:2:452:5 | call to recv | test3.cpp:448:7:448:14 | password | test3.cpp:452:10:452:17 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:448:7:448:14 | password | password |

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,33 @@ void test_member_password()
421421
decrypt_inplace(p.password); // proof that `password` was in fact encrypted
422422
}
423423
}
424+
425+
extern FILE *stdin;
426+
427+
void test_stdin_param(FILE *stream)
428+
{
429+
char password[128];
430+
431+
fgets(password, 128, stream); // GOOD: from standard input (see call below) [FALSE POSITIVE]
432+
}
433+
434+
void test_stdin()
435+
{
436+
char password[128];
437+
FILE *f = stdin;
438+
439+
fgets(password, 128, stdin); // GOOD: from standard input [FALSE POSITIVE]
440+
fgets(password, 128, f); // GOOD: from standard input [FALSE POSITIVE]
441+
test_stdin_param(stdin);
442+
}
443+
444+
int open(const char *filename, int b);
445+
446+
void test_tty()
447+
{
448+
char password[256];
449+
int f;
450+
451+
f = open("/dev/tty", val());
452+
recv(f, password, 256, val()); // GOOD: from terminal [FALSE POSITIVE]
453+
}

0 commit comments

Comments
 (0)