Skip to content

Commit 9f59bc8

Browse files
committed
C++: Naive translation to use RemoteFlow*Function.
1 parent e7c82d7 commit 9f59bc8

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import cpp
1515
import semmle.code.cpp.security.SensitiveExprs
1616
import semmle.code.cpp.dataflow.TaintTracking
17+
import semmle.code.cpp.models.interfaces.FlowSource
1718
import DataFlow::PathGraph
1819

1920
/**
@@ -38,30 +39,38 @@ abstract class NetworkSendRecv extends FunctionCall {
3839
* note: functions such as `write` may be writing to a network source or a file. We could attempt to determine which, and sort results into `cpp/cleartext-transmission` and perhaps `cpp/cleartext-storage-file`. In practice it usually isn't very important which query reports a result as long as its reported exactly once.
3940
*/
4041
class NetworkSend extends NetworkSendRecv {
41-
NetworkSend() {
42-
this.getTarget()
43-
.hasGlobalName(["send", "sendto", "sendmsg", "write", "writev", "pwritev", "pwritev2"])
44-
}
42+
RemoteFlowSinkFunction target;
43+
44+
NetworkSend() { target = this.getTarget() }
4545

4646
override Expr getSocketExpr() { result = this.getArgument(0) }
4747

48-
override Expr getDataExpr() { result = this.getArgument(1) }
48+
override Expr getDataExpr() {
49+
exists(FunctionInput input, int arg |
50+
target.hasRemoteFlowSink(input, _) and
51+
input.isParameterDeref(arg) and
52+
result = this.getArgument(arg)
53+
)
54+
}
4955
}
5056

5157
/**
5258
* A function call that receives data over a network.
5359
*/
5460
class NetworkRecv extends NetworkSendRecv {
55-
NetworkRecv() {
56-
this.getTarget()
57-
.hasGlobalName([
58-
"recv", "recvfrom", "recvmsg", "read", "pread", "readv", "preadv", "preadv2"
59-
])
60-
}
61+
RemoteFlowSourceFunction target;
62+
63+
NetworkRecv() { target = this.getTarget() }
6164

6265
override Expr getSocketExpr() { result = this.getArgument(0) }
6366

64-
override Expr getDataExpr() { result = this.getArgument(1) }
67+
override Expr getDataExpr() {
68+
exists(FunctionOutput output, int arg |
69+
target.hasRemoteFlowSource(output, _) and
70+
output.isParameterDeref(arg) and
71+
result = this.getArgument(arg)
72+
)
73+
}
6574
}
6675

6776
/**
@@ -76,7 +85,6 @@ class SensitiveSendRecvConfiguration extends TaintTracking::Configuration {
7685
override predicate isSink(DataFlow::Node sink) {
7786
exists(NetworkSendRecv transmission |
7887
sink.asExpr() = transmission.getDataExpr() and
79-
8088
// a zero file descriptor is standard input, which is not interesting for this query.
8189
not exists(Zero zero |
8290
DataFlow::localFlow(DataFlow::exprNode(zero),

0 commit comments

Comments
 (0)