mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
C#: Re-factor the CIL dataflow test to use the new API.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user