-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_taint_tracking.ql
More file actions
34 lines (26 loc) · 925 Bytes
/
10_taint_tracking.ql
File metadata and controls
34 lines (26 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @kind path-problem
*/
import cpp
import semmle.code.cpp.dataflow.TaintTracking
import DataFlow::PathGraph
class NetworkByteSwap extends Expr {
NetworkByteSwap() {
this =
any(MacroInvocation mi | mi.getMacro().hasName(["ntohs", "ntohl", "ntohll"]) | mi.getExpr())
}
}
class MemcpyCall extends FunctionCall {
MemcpyCall() { this.getTarget().hasGlobalOrStdName("memcpy") }
Expr getLengthArgument() { result = this.getArgument(2) }
}
class Config extends TaintTracking::Configuration {
Config() { this = "Config" }
override predicate isSource(DataFlow::Node node) { node.asExpr() instanceof NetworkByteSwap }
override predicate isSink(DataFlow::Node node) {
node.asExpr() = any(MemcpyCall c).getLengthArgument()
}
}
from Config cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink, source, sink, "Network byte swap flows to memcpy"