C#: Re-factor the dataflow/global tests.

This commit is contained in:
Michael Nebel
2023-03-31 14:02:33 +02:00
parent a2c7388282
commit 4023cd3b4c
5 changed files with 17 additions and 25 deletions

View File

@@ -1,18 +1,18 @@
import csharp
class Config extends DataFlow::Configuration {
Config() { this = "Config" }
override predicate isSource(DataFlow::Node source) {
module FlowConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source.asExpr().(StringLiteral).getValue() = "taint source"
or
source.asParameter().hasName("tainted")
}
override predicate isSink(DataFlow::Node sink) {
predicate isSink(DataFlow::Node sink) {
exists(MethodCall mc |
mc.getTarget().getUndecoratedName() = "Check" and
mc.getAnArgument() = sink.asExpr()
)
}
}
module Flow = DataFlow::Global<FlowConfig>;

View File

@@ -1,6 +1,6 @@
import csharp
import Common
from Config c, DataFlow::Node source, DataFlow::Node sink
where c.hasFlow(source, sink)
from DataFlow::Node source, DataFlow::Node sink
where Flow::flow(source, sink)
select sink

View File

@@ -4,10 +4,10 @@
import csharp
import Common
import DataFlow::PathGraph
import Flow::PathGraph
from Config c, DataFlow::PathNode source, DataFlow::PathNode sink, string s
from Flow::PathNode source, Flow::PathNode sink, string s
where
c.hasFlowPath(source, sink) and
Flow::flowPath(source, sink) and
s = sink.toString()
select sink, source, sink, s order by s

View File

@@ -1,12 +1,8 @@
import csharp
import Common
class TTConfig extends TaintTracking::Configuration instanceof Config {
override predicate isSource(DataFlow::Node source) { Config.super.isSource(source) }
module Taint = TaintTracking::Global<FlowConfig>;
override predicate isSink(DataFlow::Node sink) { Config.super.isSink(sink) }
}
from TTConfig c, DataFlow::Node source, DataFlow::Node sink
where c.hasFlow(source, sink)
from DataFlow::Node source, DataFlow::Node sink
where Taint::flow(source, sink)
select sink

View File

@@ -4,16 +4,12 @@
import csharp
import Common
import DataFlow::PathGraph
import Taint::PathGraph
class TTConfig extends TaintTracking::Configuration instanceof Config {
override predicate isSource(DataFlow::Node source) { Config.super.isSource(source) }
module Taint = TaintTracking::Global<FlowConfig>;
override predicate isSink(DataFlow::Node sink) { Config.super.isSink(sink) }
}
from TTConfig c, DataFlow::PathNode source, DataFlow::PathNode sink, string s
from Taint::PathNode source, Taint::PathNode sink, string s
where
c.hasFlowPath(source, sink) and
Taint::flowPath(source, sink) and
s = sink.toString()
select sink, source, sink, s