mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C#: Re-factor the callablereturnarg tests.
This commit is contained in:
@@ -10,34 +10,38 @@ private predicate outRefDef(DataFlow::ExprNode ne, int outRef) {
|
||||
)
|
||||
}
|
||||
|
||||
class Configuration extends DataFlow::Configuration {
|
||||
Configuration() { this = "Configuration" }
|
||||
module Config implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) { source instanceof DataFlow::ParameterNode }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) { source instanceof DataFlow::ParameterNode }
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
any(Callable c).canReturn(sink.asExpr()) or outRefDef(sink, _)
|
||||
}
|
||||
|
||||
override predicate isBarrier(DataFlow::Node node) {
|
||||
predicate isBarrier(DataFlow::Node node) {
|
||||
exists(AbstractValues::NullValue nv | node.(GuardedDataFlowNode).mustHaveValue(nv) |
|
||||
nv.isNull()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
predicate flowOutFromParameter(DataFlow::Configuration c, Parameter p) {
|
||||
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
|
||||
p.getCallable().canReturn(ne.getExpr()) and
|
||||
np.getParameter() = p and
|
||||
c.hasFlow(np, ne)
|
||||
)
|
||||
module FlowOut<DataFlow::GlobalFlowSig Input> {
|
||||
predicate flowOutFromParameter(Parameter p) {
|
||||
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
|
||||
p.getCallable().canReturn(ne.getExpr()) and
|
||||
np.getParameter() = p and
|
||||
Input::flow(np, ne)
|
||||
)
|
||||
}
|
||||
|
||||
predicate flowOutFromParameterOutOrRef(Parameter p, int outRef) {
|
||||
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
|
||||
outRefDef(ne, outRef) and
|
||||
np.getParameter() = p and
|
||||
Input::flow(np, ne)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
predicate flowOutFromParameterOutOrRef(DataFlow::Configuration c, Parameter p, int outRef) {
|
||||
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
|
||||
outRefDef(ne, outRef) and
|
||||
np.getParameter() = p and
|
||||
c.hasFlow(np, ne)
|
||||
)
|
||||
}
|
||||
module Data = FlowOut<DataFlow::Global<Config>>;
|
||||
|
||||
module Taint = FlowOut<TaintTracking::Global<Config>>;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import csharp
|
||||
import Common
|
||||
|
||||
from Configuration c, Parameter p, int outRefArg
|
||||
from Parameter p, int outRefArg
|
||||
where
|
||||
flowOutFromParameter(c, p) and outRefArg = -1
|
||||
Data::flowOutFromParameter(p) and outRefArg = -1
|
||||
or
|
||||
flowOutFromParameterOutOrRef(c, p, outRefArg)
|
||||
Data::flowOutFromParameterOutOrRef(p, outRefArg)
|
||||
select p.getCallable(), p.getPosition(), outRefArg
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import csharp
|
||||
import Common
|
||||
|
||||
class TaintTrackingConfiguration extends TaintTracking::Configuration {
|
||||
Configuration c;
|
||||
|
||||
TaintTrackingConfiguration() { this = "Taint " + c }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) { c.isSource(source) }
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) { c.isSink(sink) }
|
||||
|
||||
override predicate isSanitizer(DataFlow::Node node) { c.isBarrier(node) }
|
||||
}
|
||||
|
||||
from TaintTrackingConfiguration c, Parameter p, int outRefArg
|
||||
from Parameter p, int outRefArg
|
||||
where
|
||||
flowOutFromParameter(c, p) and outRefArg = -1
|
||||
Taint::flowOutFromParameter(p) and outRefArg = -1
|
||||
or
|
||||
flowOutFromParameterOutOrRef(c, p, outRefArg)
|
||||
Taint::flowOutFromParameterOutOrRef(p, outRefArg)
|
||||
select p.getCallable(), p.getPosition(), outRefArg
|
||||
|
||||
Reference in New Issue
Block a user