Skip to content

Commit 9f2f10f

Browse files
committed
JS: Make type inference flow go through ssa definition node
1 parent aa009d0 commit 9f2f10f

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,21 @@ private class AnalyzedCapturedVariable extends @variable {
3333
/**
3434
* Flow analysis for accesses to SSA variables.
3535
*/
36-
private class SsaVarAccessAnalysis extends DataFlow::AnalyzedValueNode {
37-
AnalyzedSsaDefinition def;
38-
39-
SsaVarAccessAnalysis() { astNode = def.getVariable().getAUse() }
40-
41-
override AbstractValue getALocalValue() { result = def.getAnRhsValue() }
36+
private class AnalyzedSsaDefinitionNode extends AnalyzedNode, DataFlow::SsaDefinitionNode {
37+
override AbstractValue getALocalValue() { result = ssa.(AnalyzedSsaDefinition).getAnRhsValue() }
4238
}
4339

4440
/**
4541
* Flow analysis for accesses to SSA variables.
4642
*
47-
* Unlike `SsaVarAccessAnalysis`, this only contributes to `getAValue()`, not `getALocalValue()`.
43+
* Unlike `AnalyzedSsaDefinitionNode`, this only contributes to `getAValue()`, not `getALocalValue()`.
4844
*/
49-
private class SsaVarAccessWithNonLocalAnalysis extends SsaVarAccessAnalysis {
45+
private class AnalyzedSsaDefinitionNodeWithNonLocalAnalysis extends AnalyzedSsaDefinitionNode {
5046
DataFlow::AnalyzedValueNode src;
5147

52-
SsaVarAccessWithNonLocalAnalysis() {
48+
AnalyzedSsaDefinitionNodeWithNonLocalAnalysis() {
5349
exists(VarDef varDef |
54-
varDef = def.(SsaExplicitDefinition).getDef() and
50+
varDef = ssa.(SsaExplicitDefinition).getDef() and
5551
varDef.getSource().flow() = src and
5652
src instanceof CallWithNonLocalAnalyzedReturnFlow
5753
)
@@ -60,6 +56,23 @@ private class SsaVarAccessWithNonLocalAnalysis extends SsaVarAccessAnalysis {
6056
override AbstractValue getAValue() { result = src.getAValue() }
6157
}
6258

59+
/**
60+
* Flow analysis for SSA variable uses.
61+
*
62+
* Ensures that `getAValue` propagates from the SSA definition to its use.
63+
*/
64+
private class AnalyzedSsaVariableUse extends AnalyzedValueNode {
65+
AnalyzedSsaVariableUse() {
66+
this = DataFlow::valueNode(any(SsaVariable v).getAUse())
67+
}
68+
69+
override AbstractValue getAValue() {
70+
result = AnalyzedValueNode.super.getAValue()
71+
or
72+
result = localFlowPred().getAValue()
73+
}
74+
}
75+
6376
/**
6477
* Flow analysis for `VarDef`s.
6578
*/

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
typeInferenceMismatch
2-
| addexpr.js:4:10:4:17 | source() | addexpr.js:4:5:4:17 | x |
3-
| addexpr.js:4:10:4:17 | source() | addexpr.js:6:3:6:14 | x |
4-
| addexpr.js:11:15:11:22 | source() | addexpr.js:17:5:17:18 | value |
5-
| addexpr.js:11:15:11:22 | source() | addexpr.js:19:3:19:14 | value |
62
| destruct.js:20:7:20:14 | source() | destruct.js:13:14:13:19 | [a, b] |
73
#select
84
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |

0 commit comments

Comments
 (0)