Skip to content

Commit 4048ba0

Browse files
committed
C++: Fix false positives around terminal output.
1 parent 39a2ffd commit 4048ba0

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import semmle.code.cpp.security.SensitiveExprs
1616
import semmle.code.cpp.dataflow.TaintTracking
1717
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1818
import semmle.code.cpp.models.interfaces.FlowSource
19+
import semmle.code.cpp.commons.File
1920
import DataFlow::PathGraph
2021

2122
/**
@@ -143,6 +144,13 @@ abstract class NetworkSendRecv extends FunctionCall {
143144
v.getTarget().getName() = ["stdin", "stdout", "stderr"] and
144145
g = globalValueNumber(v)
145146
)
147+
or
148+
// open of `"/dev/tty"`
149+
exists(FunctionCall fc |
150+
fopenCall(fc) and
151+
fc.getAnArgument().getValue() = "/dev/tty" and
152+
g = globalValueNumber(fc)
153+
)
146154
// (this is not exhaustive)
147155
)
148156
)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +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:448:7:448:14 | password | test3.cpp:452:10:452:17 | password |
9493
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
9594
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
9695
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
@@ -212,8 +211,6 @@ nodes
212211
| test3.cpp:400:33:400:40 | password | semmle.label | password |
213212
| test3.cpp:429:7:429:14 | password | semmle.label | password |
214213
| test3.cpp:431:8:431:15 | password | semmle.label | password |
215-
| test3.cpp:448:7:448:14 | password | semmle.label | password |
216-
| test3.cpp:452:10:452:17 | password | semmle.label | password |
217214
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
218215
| test.cpp:48:21:48:27 | call to encrypt | semmle.label | call to encrypt |
219216
| test.cpp:48:29:48:39 | thePassword | semmle.label | thePassword |
@@ -245,4 +242,3 @@ subpaths
245242
| 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 |
246243
| 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 |
247244
| 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 |
248-
| 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,5 +449,5 @@ void test_tty()
449449
int f;
450450

451451
f = open("/dev/tty", val());
452-
recv(f, password, 256, val()); // GOOD: from terminal [FALSE POSITIVE]
452+
recv(f, password, 256, val()); // GOOD: from terminal
453453
}

0 commit comments

Comments
 (0)