Skip to content

Commit 94220ec

Browse files
committed
PS: Make use of static type information in dataflow dispatch.
1 parent 92a8c84 commit 94220ec

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowDispatch.qll

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ private module TrackInstanceInput implements CallGraphConstruction::InputSig {
134134
or
135135
start.asExpr().(CfgNodes::ExprNodes::TypeNameCfgNode).getTypeName() = typename and
136136
exact = true
137+
or
138+
start.asParameter().getStaticType() = typename and
139+
exact = false
137140
}
138141

139142
newtype State = additional MkState(string typename, Boolean exact) { start0(_, typename, exact) }
@@ -174,12 +177,20 @@ Node trackInstance(string typename, boolean exact) {
174177
exact))
175178
}
176179

180+
private Type getTypeWithName(string s, boolean exact) {
181+
result.getName() = s and
182+
exact = true
183+
or
184+
result.getASubtype+().getName() = s and
185+
exact = false
186+
}
187+
177188
private CfgScope getTargetInstance(CfgNodes::CallCfgNode call) {
178189
// TODO: Also match argument/parameter types
179-
exists(Node receiver, string method, string typename, Type t |
190+
exists(Node receiver, string method, string typename, Type t, boolean exact |
180191
qualifiedCall(call, receiver, method) and
181-
receiver = trackInstance(typename, _) and
182-
t.getName() = typename
192+
receiver = trackInstance(typename, exact) and
193+
t = getTypeWithName(typename, exact)
183194
|
184195
if method = "new"
185196
then result = t.getAConstructor().getBody()

0 commit comments

Comments
 (0)