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

Skip to content

Commit 8c96f5f

Browse files
committed
JS: tweak global flow for closure modules
1 parent 5502627 commit 8c96f5f

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class AnalyzedNode extends DataFlow::Node {
4747
*/
4848
AnalyzedNode localFlowPred() { result = getAPredecessor() }
4949

50+
/**
51+
* Gets another data flow node whose value flows into this node in a global step
52+
* (this is, involvign global variables).
53+
*/
54+
AnalyzedNode globalFlowPred() { none() }
55+
5056
/**
5157
* Gets an abstract value that this node may evaluate to at runtime.
5258
*
@@ -57,7 +63,9 @@ class AnalyzedNode extends DataFlow::Node {
5763
* instances is also performed.
5864
*/
5965
cached
60-
AbstractValue getAValue() { result = getALocalValue() }
66+
AbstractValue getAValue() {
67+
result = getALocalValue()
68+
}
6169

6270
/**
6371
* INTERNAL: Do not use.
@@ -82,6 +90,9 @@ class AnalyzedNode extends DataFlow::Node {
8290
exists(DataFlow::Incompleteness cause |
8391
isIncomplete(cause) and result = TIndefiniteAbstractValue(cause)
8492
)
93+
or
94+
result = globalFlowPred().getALocalValue() and
95+
shouldTrackGlobally(result)
8596
}
8697

8798
/** Gets a type inferred for this node. */
@@ -282,3 +293,8 @@ private class AnalyzedAsyncFunction extends AnalyzedFunction {
282293

283294
override AbstractValue getAReturnValue() { result = TAbstractOtherObject() }
284295
}
296+
297+
/**
298+
* Holds if the given value should be propagated along `globalFlowPred()` edges.
299+
*/
300+
private predicate shouldTrackGlobally(AbstractValue value) { value instanceof AbstractCallable }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,11 @@ private class AnalyzedClosureGlobalAccessPath extends AnalyzedNode, AnalyzedProp
360360

361361
AnalyzedClosureGlobalAccessPath() { accessPath = Closure::getLibraryAccessPath(this) }
362362

363-
override AnalyzedNode localFlowPred() {
363+
override AnalyzedNode globalFlowPred() {
364364
exists(DataFlow::PropWrite write |
365365
Closure::getWrittenLibraryAccessPath(write) = accessPath and
366366
result = write.getRhs()
367367
)
368-
or
369-
result = AnalyzedNode.super.localFlowPred()
370368
}
371369

372370
override predicate reads(AbstractValue base, string propName) {

0 commit comments

Comments
 (0)