Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a2f87f

Browse files
committed
JS: AdditionalTypeTrackingStep -> SharedTypeTrackingStep
1 parent b8049f1 commit 3a2f87f

3 files changed

Lines changed: 98 additions & 28 deletions

File tree

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
private import javascript
1010
private import internal.FlowSteps
1111
private import internal.StepSummary
12+
private import internal.Unit
1213
private import semmle.javascript.internal.CachedStages
1314

1415
private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalPropertyName prop)
@@ -328,6 +329,71 @@ module TypeBackTracker {
328329
}
329330

330331
/**
332+
* A data flow edge that should be followed by type tracking.
333+
*
334+
* Unlike `SharedFlowStep`, this type of edge does not affect
335+
* the local data flow graph, and is not used by data-flow configurations.
336+
*
337+
* Note: For performance reasons, all subclasses of this class should be part
338+
* of the standard library. For query-specific steps, consider including the
339+
* custom steps in the type-tracking predicate itself.
340+
*/
341+
class SharedTypeTrackingStep extends Unit {
342+
/**
343+
* Holds if type-tracking should step from `pred` to `succ`.
344+
*/
345+
predicate step(DataFlow::Node pred, DataFlow::Node succ) { none() }
346+
347+
/**
348+
* Holds if type-tracking should step from `pred` into the `prop` property of `succ`.
349+
*/
350+
predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) { none() }
351+
352+
/**
353+
* Holds if type-tracking should step from the `prop` property of `pred` to `succ`.
354+
*/
355+
predicate loadStep(DataFlow::Node pred, DataFlow::Node succ, string prop) { none() }
356+
357+
/**
358+
* Holds if type-tracking should step from the `prop` property of `pred` to the same property in `succ`.
359+
*/
360+
predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) { none() }
361+
}
362+
363+
/** Provides access to the steps contributed by subclasses of `SharedTypeTrackingStep`. */
364+
module SharedTypeTrackingStep {
365+
/**
366+
* Holds if type-tracking should step from `pred` to `succ`.
367+
*/
368+
predicate step(DataFlow::Node pred, DataFlow::Node succ) {
369+
any(SharedTypeTrackingStep s).step(pred, succ)
370+
}
371+
372+
/**
373+
* Holds if type-tracking should step from `pred` into the `prop` property of `succ`.
374+
*/
375+
predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
376+
any(SharedTypeTrackingStep s).storeStep(pred, succ, prop)
377+
}
378+
379+
/**
380+
* Holds if type-tracking should step from the `prop` property of `pred` to `succ`.
381+
*/
382+
predicate loadStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
383+
any(SharedTypeTrackingStep s).loadStep(pred, succ, prop)
384+
}
385+
386+
/**
387+
* Holds if type-tracking should step from the `prop` property of `pred` to the same property in `succ`.
388+
*/
389+
predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
390+
any(SharedTypeTrackingStep s).loadStoreStep(pred, succ, prop)
391+
}
392+
}
393+
394+
/**
395+
* DEPRECATED. Use `SharedTypeTrackingStep` instead.
396+
*
331397
* A data flow edge that should be followed by type tracking.
332398
*
333399
* Unlike `AdditionalFlowStep`, this type of edge does not affect
@@ -337,7 +403,10 @@ module TypeBackTracker {
337403
* of the standard library. For query-specific steps, consider including the
338404
* custom steps in the type-tracking predicate itself.
339405
*/
340-
abstract class AdditionalTypeTrackingStep extends DataFlow::Node {
406+
deprecated class AdditionalTypeTrackingStep = LegacyTypeTrackingStep;
407+
408+
// Internal version of AdditionalTypeTrackingStep that we can reference without deprecation warnings.
409+
abstract private class LegacyTypeTrackingStep extends DataFlow::Node {
341410
/**
342411
* Holds if type-tracking should step from `pred` to `succ`.
343412
*/
@@ -358,3 +427,21 @@ abstract class AdditionalTypeTrackingStep extends DataFlow::Node {
358427
*/
359428
predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) { none() }
360429
}
430+
431+
private class LegacyStepAsSharedTypeTrackingStep extends SharedTypeTrackingStep {
432+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
433+
any(LegacyTypeTrackingStep s).step(pred, succ)
434+
}
435+
436+
override predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
437+
any(LegacyTypeTrackingStep s).storeStep(pred, succ, prop)
438+
}
439+
440+
override predicate loadStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
441+
any(LegacyTypeTrackingStep s).loadStep(pred, succ, prop)
442+
}
443+
444+
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
445+
any(LegacyTypeTrackingStep s).loadStoreStep(pred, succ, prop)
446+
}
447+
}

javascript/ql/src/semmle/javascript/dataflow/internal/PreCallGraphStep.qll

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private class Unit extends TUnit {
1616
* Internal extension point for adding flow edges prior to call graph construction
1717
* and type tracking.
1818
*
19-
* Steps added here will be added to both `AdditionalFlowStep` and `AdditionalTypeTrackingStep`.
19+
* Steps added here will be added to both `SharedFlowStep` and `SharedTypeTrackingStep`.
2020
*
2121
* Contributing steps that rely on type tracking will lead to negative recursion.
2222
*/
@@ -77,18 +77,6 @@ module PreCallGraphStep {
7777
}
7878
}
7979

80-
private class NodeWithPreCallGraphStep extends DataFlow::Node {
81-
NodeWithPreCallGraphStep() {
82-
PreCallGraphStep::step(this, _)
83-
or
84-
PreCallGraphStep::storeStep(this, _, _)
85-
or
86-
PreCallGraphStep::loadStep(this, _, _)
87-
or
88-
PreCallGraphStep::loadStoreStep(this, _, _)
89-
}
90-
}
91-
9280
private class SharedFlowStepFromPreCallGraph extends DataFlow::SharedFlowStep {
9381
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
9482
PreCallGraphStep::step(pred, succ)
@@ -107,25 +95,20 @@ private class SharedFlowStepFromPreCallGraph extends DataFlow::SharedFlowStep {
10795
}
10896
}
10997

110-
private class AdditionalTypeTrackingStepFromPreCallGraph extends NodeWithPreCallGraphStep,
111-
DataFlow::AdditionalTypeTrackingStep {
98+
private class SharedTypeTrackingStepFromPreCallGraph extends DataFlow::SharedTypeTrackingStep {
11299
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
113-
pred = this and
114-
PreCallGraphStep::step(this, succ)
100+
PreCallGraphStep::step(pred, succ)
115101
}
116102

117103
override predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
118-
pred = this and
119-
PreCallGraphStep::storeStep(this, succ, prop)
104+
PreCallGraphStep::storeStep(pred, succ, prop)
120105
}
121106

122107
override predicate loadStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
123-
pred = this and
124-
PreCallGraphStep::loadStep(this, succ, prop)
108+
PreCallGraphStep::loadStep(pred, succ, prop)
125109
}
126110

127111
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
128-
pred = this and
129-
PreCallGraphStep::loadStoreStep(this, succ, prop)
112+
PreCallGraphStep::loadStoreStep(pred, succ, prop)
130113
}
131114
}

javascript/ql/src/semmle/javascript/dataflow/internal/StepSummary.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ module StepSummary {
111111
basicLoadStep(pred, succ, prop) and
112112
summary = LoadStep(prop)
113113
or
114-
any(AdditionalTypeTrackingStep st).storeStep(pred, succ, prop) and
114+
SharedTypeTrackingStep::storeStep(pred, succ, prop) and
115115
summary = StoreStep(prop)
116116
or
117-
any(AdditionalTypeTrackingStep st).loadStep(pred, succ, prop) and
117+
SharedTypeTrackingStep::loadStep(pred, succ, prop) and
118118
summary = LoadStep(prop)
119119
or
120-
any(AdditionalTypeTrackingStep st).loadStoreStep(pred, succ, prop) and
120+
SharedTypeTrackingStep::loadStoreStep(pred, succ, prop) and
121121
summary = CopyStep(prop)
122122
)
123123
or
124-
any(AdditionalTypeTrackingStep st).step(pred, succ) and
124+
SharedTypeTrackingStep::step(pred, succ) and
125125
summary = LevelStep()
126126
or
127127
// Store to global access path

0 commit comments

Comments
 (0)