Skip to content

Commit 79735f5

Browse files
committed
C++: Add test case.
1 parent a77a6ec commit 79735f5

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edges
77
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input indirection |
88
subpaths
99
nodes
10+
| test2.cpp:103:3:103:6 | call to gets | semmle.label | call to gets |
11+
| test2.cpp:103:3:103:6 | call to gets | semmle.label | call to gets |
12+
| test2.cpp:103:3:103:6 | call to gets | semmle.label | call to gets |
1013
| test.cpp:54:17:54:20 | argv | semmle.label | argv |
1114
| test.cpp:54:17:54:20 | argv | semmle.label | argv |
1215
| test.cpp:58:25:58:29 | input | semmle.label | input |
@@ -15,4 +18,5 @@ nodes
1518
| test.cpp:58:25:58:29 | input indirection | semmle.label | input indirection |
1619
| test.cpp:58:25:58:29 | input indirection | semmle.label | input indirection |
1720
#select
21+
| test2.cpp:103:3:103:6 | call to gets | test2.cpp:103:3:103:6 | call to gets | test2.cpp:103:3:103:6 | call to gets | This write into buffer 'password' may contain unencrypted data from $@ | test2.cpp:103:3:103:6 | call to gets | user input (gets) |
1822
| test.cpp:58:3:58:9 | call to sprintf | test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input | This write into buffer 'passwd' may contain unencrypted data from $@ | test.cpp:54:17:54:20 | argv | user input (argv) |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
edges
2+
| test2.cpp:101:8:101:15 | password | test2.cpp:103:8:103:15 | password |
23
| test3.cpp:17:28:17:36 | password1 | test3.cpp:22:15:22:23 | password1 |
34
| test3.cpp:17:51:17:59 | password2 | test3.cpp:26:15:26:23 | password2 |
45
| test3.cpp:45:8:45:15 | password | test3.cpp:47:15:47:22 | password |
@@ -90,6 +91,8 @@ edges
9091
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
9192
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:29:76:39 | thePassword |
9293
nodes
94+
| test2.cpp:101:8:101:15 | password | semmle.label | password |
95+
| test2.cpp:103:8:103:15 | password | semmle.label | password |
9396
| test3.cpp:17:28:17:36 | password1 | semmle.label | password1 |
9497
| test3.cpp:17:51:17:59 | password2 | semmle.label | password2 |
9598
| test3.cpp:22:15:22:23 | password1 | semmle.label | password1 |
@@ -210,6 +213,7 @@ subpaths
210213
| test3.cpp:316:11:316:19 | password1 | test3.cpp:283:20:283:23 | data | test3.cpp:283:20:283:23 | data | test3.cpp:316:11:316:19 | ref arg password1 |
211214
| test3.cpp:324:11:324:14 | data | test3.cpp:293:20:293:23 | data | test3.cpp:293:20:293:23 | data | test3.cpp:324:11:324:14 | ref arg data |
212215
#select
216+
| test2.cpp:103:3:103:6 | call to gets | test2.cpp:101:8:101:15 | password | test2.cpp:103:8:103:15 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test2.cpp:101:8:101:15 | password | password |
213217
| test3.cpp:22:3:22:6 | call to send | test3.cpp:17:28:17:36 | password1 | test3.cpp:22:15:22:23 | password1 | This operation transmits 'password1', which may contain unencrypted sensitive data from $@ | test3.cpp:17:28:17:36 | password1 | password1 |
214218
| test3.cpp:26:3:26:6 | call to send | test3.cpp:17:51:17:59 | password2 | test3.cpp:26:15:26:23 | password2 | This operation transmits 'password2', which may contain unencrypted sensitive data from $@ | test3.cpp:17:51:17:59 | password2 | password2 |
215219
| test3.cpp:47:3:47:6 | call to recv | test3.cpp:45:8:45:15 | password | test3.cpp:47:15:47:22 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:45:8:45:15 | password | password |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ void tests(FILE *log, myStruct &s)
9292
fprintf(log, "log: %s", buffer); // BAD [NOT DETECTED]
9393
}
9494
}
95+
96+
char *gets(char *s);
97+
98+
void test_gets()
99+
{
100+
{
101+
char password[1024];
102+
103+
gets(password); // BAD [but FALSE POSITIVE from cpp/cleartext-transmission]
104+
}
105+
}

0 commit comments

Comments
 (0)