File tree Expand file tree Collapse file tree
src/semmle/javascript/dataflow
test/library-tests/RecursionPrevention Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,7 +34,11 @@ private import semmle.javascript.internal.CachedStages
3434 * ```
3535 */
3636class SourceNode extends DataFlow:: Node {
37- SourceNode ( ) { this instanceof SourceNode:: Range }
37+ SourceNode ( ) {
38+ this instanceof SourceNode:: Range
39+ or
40+ none ( ) and this instanceof SourceNode:: Internal:: RecursionGuard
41+ }
3842
3943 /**
4044 * Holds if this node flows into `sink` in zero or more local (that is,
@@ -329,6 +333,12 @@ module SourceNode {
329333 DataFlow:: functionReturnNode ( this , _)
330334 }
331335 }
336+
337+ /** INTERNAL. DO NOT USE. */
338+ module Internal {
339+ /** An empty class that some tests are using to enforce that SourceNode is non-recursive. */
340+ abstract class RecursionGuard extends DataFlow:: Node { }
341+ }
332342}
333343
334344deprecated class DefaultSourceNode extends SourceNode {
Original file line number Diff line number Diff line change 1+ | Success |
Original file line number Diff line number Diff line change 1+ /**
2+ * Test that fails to compile if the domain of `SourceNode::Range` depends on `SourceNode` (recursively).
3+ *
4+ * This tests adds a negative dependency `SourceNode --!--> SourceNode::Range`
5+ * so that the undesired edge `SourceNode::Range --> SourceNode` completes a negative cycle.
6+ */
7+
8+ import javascript
9+
10+ class BadSourceNodeRange extends DataFlow:: SourceNode:: Internal:: RecursionGuard {
11+ BadSourceNodeRange ( ) {
12+ not this instanceof DataFlow:: SourceNode:: Range
13+ }
14+ }
15+
16+ select "Success"
You can’t perform that action at this time.
0 commit comments