C#: Re-factor the CIL dataflow test to use the new API.

This commit is contained in:
Michael Nebel
2023-05-08 14:05:37 +02:00
parent ededd466cb
commit bd0133630d

View File

@@ -3,9 +3,9 @@
*/
import csharp
import DataFlow
import Flow::PathGraph
private predicate relevantPathNode(PathNode n) {
private predicate relevantPathNode(Flow::PathNode n) {
exists(File f | f = n.getNode().getLocation().getFile() |
f.fromSource()
or
@@ -13,35 +13,37 @@ private predicate relevantPathNode(PathNode n) {
)
}
query predicate edges(PathNode a, PathNode b) {
PathGraph::edges(a, b) and
query predicate edges(Flow::PathNode a, Flow::PathNode b) {
Flow::PathGraph::edges(a, b) and
relevantPathNode(a) and
relevantPathNode(b)
}
query predicate nodes(PathNode n, string key, string val) {
PathGraph::nodes(n, key, val) and
query predicate nodes(Flow::PathNode n, string key, string val) {
Flow::PathGraph::nodes(n, key, val) and
relevantPathNode(n)
}
query predicate subpaths(PathNode arg, PathNode par, PathNode ret, PathNode out) {
PathGraph::subpaths(arg, par, ret, out) and
query predicate subpaths(
Flow::PathNode arg, Flow::PathNode par, Flow::PathNode ret, Flow::PathNode out
) {
Flow::PathGraph::subpaths(arg, par, ret, out) and
relevantPathNode(arg) and
relevantPathNode(par) and
relevantPathNode(ret) and
relevantPathNode(out)
}
class FlowConfig extends Configuration {
FlowConfig() { this = "FlowConfig" }
module FlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof Literal }
override predicate isSource(Node source) { source.asExpr() instanceof Literal }
override predicate isSink(Node sink) {
predicate isSink(DataFlow::Node sink) {
exists(LocalVariable decl | sink.asExpr() = decl.getInitializer())
}
}
from PathNode source, PathNode sink, FlowConfig config
where config.hasFlowPath(source, sink)
module Flow = DataFlow::Global<FlowConfig>;
from Flow::PathNode source, Flow::PathNode sink
where Flow::flowPath(source, sink)
select source, sink, sink, "$@", sink, sink.toString()