Skip to content

Commit 39a2ffd

Browse files
committed
C++: Fix false positives around 'stdin'.
1 parent cc20969 commit 39a2ffd

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ abstract class NetworkSendRecv extends FunctionCall {
137137
forex(Expr arg | arg = fc.getAnArgument() | arg instanceof Literal) and
138138
g = globalValueNumber(fc)
139139
)
140-
// (this is far from exhaustive)
140+
or
141+
// variable called `stdin`, `stdout` or `stderr`
142+
exists(VariableAccess v |
143+
v.getTarget().getName() = ["stdin", "stdout", "stderr"] and
144+
g = globalValueNumber(v)
145+
)
146+
// (this is not exhaustive)
141147
)
142148
)
143149
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ edges
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 |
9292
| 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 |
9593
| test3.cpp:448:7:448:14 | password | test3.cpp:452:10:452:17 | password |
9694
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
9795
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
@@ -214,9 +212,6 @@ nodes
214212
| test3.cpp:400:33:400:40 | password | semmle.label | password |
215213
| test3.cpp:429:7:429:14 | password | semmle.label | password |
216214
| 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 |
220215
| test3.cpp:448:7:448:14 | password | semmle.label | password |
221216
| test3.cpp:452:10:452:17 | password | semmle.label | password |
222217
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
@@ -250,6 +245,4 @@ subpaths
250245
| 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 |
251246
| 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 |
252247
| 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 |
255248
| 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ void test_stdin()
436436
char password[128];
437437
FILE *f = stdin;
438438

439-
fgets(password, 128, stdin); // GOOD: from standard input [FALSE POSITIVE]
440-
fgets(password, 128, f); // GOOD: from standard input [FALSE POSITIVE]
439+
fgets(password, 128, stdin); // GOOD: from standard input
440+
fgets(password, 128, f); // GOOD: from standard input
441441
test_stdin_param(stdin);
442442
}
443443

0 commit comments

Comments
 (0)