Skip to content

Commit 8eb7c36

Browse files
Use flow path in alerts
1 parent e5f9788 commit 8eb7c36

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

python/ql/src/Variables/LoopVariableCapture.ql

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Loop variable capture
33
* @description Capture of a loop variable is not the same as capturing the value of a loop variable, and may be erroneous.
4-
* @kind problem
4+
* @kind path-problem
55
* @tags correctness
66
* @problem.severity error
77
* @sub-severity low
@@ -60,13 +60,23 @@ module EscapingCaptureFlowSig implements DataFlow::ConfigSig {
6060

6161
module EscapingCaptureFlow = DataFlow::Global<EscapingCaptureFlowSig>;
6262

63-
predicate escapingCapture(CallableExpr capturing, Loop loop, Variable var) {
63+
import EscapingCaptureFlow::PathGraph
64+
65+
predicate escapingCapture(
66+
CallableExpr capturing, Loop loop, Variable var, EscapingCaptureFlow::PathNode source,
67+
EscapingCaptureFlow::PathNode sink
68+
) {
6469
capturesLoopVariable(capturing, loop, var) and
65-
EscapingCaptureFlow::flow(DataFlow::exprNode(capturing), _)
70+
capturing = source.getNode().asExpr() and
71+
EscapingCaptureFlow::flowPath(source, sink)
6672
}
6773

68-
from CallableExpr capturing, AstNode loop, Variable var, string descr
74+
from
75+
CallableExpr capturing, AstNode loop, Variable var, string descr,
76+
EscapingCaptureFlow::PathNode source, EscapingCaptureFlow::PathNode sink
6977
where
70-
escapingCapture(capturing, loop, var) and
78+
escapingCapture(capturing, loop, var, source, sink) and
7179
if capturing instanceof Lambda then descr = "lambda" else descr = "function"
72-
select capturing, "This " + descr + " captures the loop variable $@.", loop, var.getId()
80+
select capturing, source, sink,
81+
"This " + descr + " captures the loop variable $@, and may escape the loop by being stored $@.",
82+
loop, var.getId(), sink, "here"

0 commit comments

Comments
 (0)