Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 112ced9

Browse files
committed
step-31
1 parent 43b0d38 commit 112ced9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import cpp
6+
import semmle.code.cpp.dataflow.TaintTracking
7+
import DataFlow::PathGraph
8+
9+
class NetworkRead extends Expr {
10+
NetworkRead() {
11+
exists(MacroInvocation i | this = i.getExpr()
12+
and i.getMacroName().regexpMatch("ntoh(l|ll|s)"))
13+
}
14+
}
15+
16+
class Config extends TaintTracking::Configuration {
17+
Config() { this = "NetworkToMemFuncLength" }
18+
19+
override predicate isSource(DataFlow::Node source) {
20+
source.asExpr() instanceof NetworkRead
21+
}
22+
23+
override predicate isSink(DataFlow::Node sink) {
24+
exists (FunctionCall fc |
25+
sink.asExpr() = fc.getArgument(2) and fc.getTarget().getName()= "memcpy")
26+
}
27+
}
28+
29+
from Config cfg, DataFlow::PathNode source, DataFlow::PathNode sink
30+
where cfg.hasFlowPath(source, sink)
31+
select sink, source, sink, "ntoh flows to memcpy"

courses/cpp/uboot/image/config/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"21_memcpy_calls.ql": "step-21.csv",
99
"22_macro_invocations.ql": "step-22.csv",
1010
"23_macro_expressions.ql": "step_23.csv",
11-
"24_class_network_reads.ql": "step-24.csv"
11+
"24_class_network_reads.ql": "step-24.csv",
12+
"31_taint_tracking": false
1213
}
1314
}

0 commit comments

Comments
 (0)