mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
C#: Re-factor LambdaDataFlow to use the new API.
This commit is contained in:
@@ -37,19 +37,19 @@ predicate inForeachStmtBody(ForeachStmt loop, Element e) {
|
||||
)
|
||||
}
|
||||
|
||||
class LambdaDataFlowConfiguration extends DataFlow::Configuration {
|
||||
LambdaDataFlowConfiguration() { this = "LambdaDataFlowConfiguration" }
|
||||
module LambdaDataFlowConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) { lambdaCapturesLoopVariable(source.asExpr(), _, _) }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) {
|
||||
lambdaCapturesLoopVariable(source.asExpr(), _, _)
|
||||
}
|
||||
predicate isSink(DataFlow::Node sink) { exists(getAssignmentTarget(sink.asExpr())) }
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) { exists(getAssignmentTarget(sink.asExpr())) }
|
||||
module LambdaDataFlow {
|
||||
private import DataFlow::Global<LambdaDataFlowConfig>
|
||||
|
||||
predicate capturesLoopVarAndIsStoredIn(
|
||||
AnonymousFunctionExpr lambda, Variable loopVar, Element storage
|
||||
) {
|
||||
exists(DataFlow::Node sink | this.hasFlow(DataFlow::exprNode(lambda), sink) |
|
||||
exists(DataFlow::Node sink | flow(DataFlow::exprNode(lambda), sink) |
|
||||
storage = getAssignmentTarget(sink.asExpr())
|
||||
) and
|
||||
exists(ForeachStmt loop | lambdaCapturesLoopVariable(lambda, loop, loopVar) |
|
||||
@@ -109,7 +109,7 @@ predicate declaredInsideLoop(ForeachStmt loop, LocalVariable v) {
|
||||
)
|
||||
}
|
||||
|
||||
from LambdaDataFlowConfiguration c, AnonymousFunctionExpr lambda, Variable loopVar, Element storage
|
||||
where c.capturesLoopVarAndIsStoredIn(lambda, loopVar, storage)
|
||||
from AnonymousFunctionExpr lambda, Variable loopVar, Element storage
|
||||
where LambdaDataFlow::capturesLoopVarAndIsStoredIn(lambda, loopVar, storage)
|
||||
select lambda, "Function which may be stored in $@ captures variable $@.", storage,
|
||||
storage.toString(), loopVar, loopVar.getName()
|
||||
|
||||
Reference in New Issue
Block a user