Skip to content

Commit 40f671a

Browse files
committed
step 10
1 parent d0e767a commit 40f671a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

10_taint_tracking.ql

+33
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1+
/**
2+
* @kind path-problem
3+
*/
14

5+
import cpp
6+
import semmle.code.cpp.dataflow.TaintTracking
7+
import DataFlow::PathGraph
8+
9+
class NetworkByteSwap extends Expr {
10+
NetworkByteSwap () {
11+
exists( MacroInvocation mi |
12+
mi.getMacroName() = "ntohs" or mi.getMacroName() = "ntohl" or mi.getMacroName() = "ntohll" |
13+
this = mi.getExpr()
14+
)
15+
}
16+
}
17+
18+
class Config extends TaintTracking::Configuration {
19+
Config() { this = "NetworkToMemFuncLength" }
20+
21+
override predicate isSource(DataFlow::Node source) {
22+
source.asExpr() instanceof NetworkByteSwap
23+
}
24+
override predicate isSink(DataFlow::Node sink) {
25+
exists (FunctionCall call |
26+
sink.asExpr() = call.getArgument(2) and
27+
call.getTarget().getName() = "memcpy"
28+
)
29+
}
30+
}
31+
32+
from Config cfg, DataFlow::PathNode source, DataFlow::PathNode sink
33+
where cfg.hasFlowPath(source, sink)
34+
select sink, source, sink, "Network byte swap flows to memcpy"

0 commit comments

Comments
 (0)