Skip to content

Commit 2ecef33

Browse files
authored
Merge pull request github#3299 from asger-semmle/js/flows-to-redundant-check
Approved by esbena
2 parents 80c20cb + bccc27f commit 2ecef33

File tree

1 file changed

+19
-5
lines changed
  • javascript/ql/src/semmle/javascript/dataflow

1 file changed

+19
-5
lines changed

javascript/ql/src/semmle/javascript/dataflow/Sources.qll

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ class SourceNode extends DataFlow::Node {
3939
* Holds if this node flows into `sink` in zero or more local (that is,
4040
* intra-procedural) steps.
4141
*/
42-
cached
43-
predicate flowsTo(DataFlow::Node sink) {
44-
sink = this or
45-
flowsTo(sink.getAPredecessor())
46-
}
42+
predicate flowsTo(DataFlow::Node sink) { hasLocalSource(sink, this) }
4743

4844
/**
4945
* Holds if this node flows into `sink` in zero or more local (that is,
@@ -195,6 +191,24 @@ class SourceNode extends DataFlow::Node {
195191
}
196192
}
197193

194+
/**
195+
* Holds if `source` is a `SourceNode` that can reach `sink` via local flow steps.
196+
*
197+
* The slightly backwards parametering ordering is to force correct indexing.
198+
*/
199+
cached
200+
private predicate hasLocalSource(DataFlow::Node sink, DataFlow::Node source) {
201+
// Declaring `source` to be a `SourceNode` currently causes a redundant check in the
202+
// recursive case, so instead we check it explicitly here.
203+
source = sink and
204+
source instanceof DataFlow::SourceNode
205+
or
206+
exists(DataFlow::Node mid |
207+
hasLocalSource(mid, source) and
208+
DataFlow::localFlowStep(mid, sink)
209+
)
210+
}
211+
198212
module SourceNode {
199213
/**
200214
* A data flow node that should be considered a source node.

0 commit comments

Comments
 (0)