Skip to content

Commit 9efc3ec

Browse files
committed
PS: Make dataflow compile again.
1 parent cc13922 commit 9efc3ec

File tree

6 files changed

+203
-249
lines changed

6 files changed

+203
-249
lines changed

powershell/ql/lib/semmle/code/powershell/dataflow/FlowSummary.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
5353
* calls to a method with the same name are considered relevant.
5454
*/
5555
abstract class SimpleSummarizedCallable extends SummarizedCallable {
56-
Call c;
56+
CallExpr c;
5757

5858
bindingset[this]
5959
SimpleSummarizedCallable() { c.getName() = this }
6060

61-
final override Call getACall() { result = c }
61+
final override CallExpr getACall() { result = c }
6262

63-
final override Call getACallSimple() { result = c }
63+
final override CallExpr getACallSimple() { result = c }
6464
}

powershell/ql/lib/semmle/code/powershell/dataflow/flowsources/Local.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ abstract class EnvironmentVariableSource extends LocalFlowSource {
3131
}
3232

3333
private class EnvironmentVariableEnv extends EnvironmentVariableSource {
34-
EnvironmentVariableEnv() {
35-
this.asExpr().getExpr().(VarReadAccess).getVariable() instanceof EnvVariable
36-
}
34+
EnvironmentVariableEnv() { this.asExpr().getExpr() instanceof EnvVariable }
3735
}
3836

3937
private class ExternalEnvironmentVariableSource extends EnvironmentVariableSource {
@@ -61,7 +59,7 @@ private class ExternalCommandLineArgumentSource extends CommandLineArgumentSourc
6159
* A data flow source that represents the parameters of the `Main` method of a program.
6260
*/
6361
private class MainMethodArgumentSource extends CommandLineArgumentSource {
64-
MainMethodArgumentSource() { this.asParameter().getFunction() instanceof TopLevel }
62+
MainMethodArgumentSource() { this.asParameter().getParent() instanceof TopLevelScriptBlock }
6563
}
6664

6765
/**

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import DataFlowPublic
55
private import semmle.code.powershell.typetracking.internal.TypeTrackingImpl
66
private import FlowSummaryImpl as FlowSummaryImpl
77
private import semmle.code.powershell.dataflow.FlowSummary
8+
private import SsaImpl as SsaImpl
89
private import codeql.util.Boolean
910
private import codeql.util.Unit
1011

@@ -39,10 +40,10 @@ abstract class LibraryCallable extends string {
3940
LibraryCallable() { any() }
4041

4142
/** Gets a call to this library callable. */
42-
Call getACall() { none() }
43+
CallExpr getACall() { none() }
4344

4445
/** Same as `getACall()` except this does not depend on the call graph or API graph. */
45-
Call getACallSimple() { none() }
46+
CallExpr getACallSimple() { none() }
4647
}
4748

4849
/** A callable defined in library code, which should be taken into account in type tracking. */
@@ -90,7 +91,7 @@ abstract class DataFlowCall extends TDataFlowCall {
9091
abstract DataFlowCallable getEnclosingCallable();
9192

9293
/** Gets the underlying source code call, if any. */
93-
abstract CfgNodes::CallCfgNode asCall();
94+
abstract CfgNodes::ExprNodes::CallExprCfgNode asCall();
9495

9596
/** Gets a textual representation of this call. */
9697
abstract string toString();
@@ -130,19 +131,19 @@ class SummaryCall extends DataFlowCall, TSummaryCall {
130131

131132
override DataFlowCallable getEnclosingCallable() { result.asLibraryCallable() = c }
132133

133-
override CfgNodes::CallCfgNode asCall() { none() }
134+
override CfgNodes::ExprNodes::CallExprCfgNode asCall() { none() }
134135

135136
override string toString() { result = "[summary] call to " + receiver + " in " + c }
136137

137138
override EmptyLocation getLocation() { any() }
138139
}
139140

140141
class NormalCall extends DataFlowCall, TNormalCall {
141-
private CfgNodes::CallCfgNode c;
142+
private CfgNodes::ExprNodes::CallExprCfgNode c;
142143

143144
NormalCall() { this = TNormalCall(c) }
144145

145-
override CfgNodes::CallCfgNode asCall() { result = c }
146+
override CfgNodes::ExprNodes::CallExprCfgNode asCall() { result = c }
146147

147148
override DataFlowCallable getEnclosingCallable() { result = TCfgScope(c.getScope()) }
148149

@@ -161,7 +162,7 @@ private module TrackInstanceInput implements CallGraphConstruction::InputSig {
161162
start.(ObjectCreationNode).getObjectCreationNode().getConstructedTypeName() = typename and
162163
exact = true
163164
or
164-
start.asExpr().(CfgNodes::ExprNodes::TypeNameCfgNode).getTypeName() = typename and
165+
start.asExpr().(CfgNodes::ExprNodes::TypeNameExprCfgNode).getName() = typename and
165166
exact = true
166167
or
167168
start.asParameter().getStaticType() = typename and
@@ -195,7 +196,9 @@ private module TrackInstanceInput implements CallGraphConstruction::InputSig {
195196
predicate filter(Node n, Unit u) { none() }
196197
}
197198

198-
private predicate qualifiedCall(CfgNodes::CallCfgNode call, Node receiver, string method) {
199+
private predicate qualifiedCall(
200+
CfgNodes::ExprNodes::CallExprCfgNode call, Node receiver, string method
201+
) {
199202
call.getQualifier() = receiver.asExpr() and
200203
call.getName() = method
201204
}
@@ -214,7 +217,7 @@ private Type getTypeWithName(string s, boolean exact) {
214217
exact = false
215218
}
216219

217-
private CfgScope getTargetInstance(CfgNodes::CallCfgNode call) {
220+
private CfgScope getTargetInstance(CfgNodes::ExprNodes::CallExprCfgNode call) {
218221
// TODO: Also match argument/parameter types
219222
exists(Node receiver, string method, string typename, Type t, boolean exact |
220223
qualifiedCall(call, receiver, method) and
@@ -236,7 +239,7 @@ class AdditionalCallTarget extends Unit {
236239
/**
237240
* Gets a viable target for `call`.
238241
*/
239-
abstract DataFlowCallable viableTarget(CfgNodes::CallCfgNode call);
242+
abstract DataFlowCallable viableTarget(CfgNodes::ExprNodes::CallExprCfgNode call);
240243
}
241244

242245
/** Holds if `call` may resolve to the returned summarized library method. */
@@ -256,7 +259,7 @@ private module Cached {
256259

257260
cached
258261
newtype TDataFlowCall =
259-
TNormalCall(CfgNodes::CallCfgNode c) or
262+
TNormalCall(CfgNodes::ExprNodes::CallExprCfgNode c) or
260263
TSummaryCall(
261264
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver
262265
) {
@@ -283,7 +286,7 @@ private module Cached {
283286
FlowSummaryImpl::ParsePositions::isParsedKeywordParameterPosition(_, name)
284287
} or
285288
TPositionalArgumentPosition(int pos, NamedSet ns) {
286-
exists(CfgNodes::CallCfgNode call |
289+
exists(CfgNodes::ExprNodes::CallExprCfgNode call |
287290
call = ns.getABindingCall() and
288291
exists(call.getArgument(pos))
289292
)
@@ -297,7 +300,7 @@ private module Cached {
297300
TThisParameterPosition() or
298301
TKeywordParameter(string name) { name = any(Argument p).getName() } or
299302
TPositionalParameter(int pos, NamedSet ns) {
300-
exists(CfgNodes::CallCfgNode call |
303+
exists(CfgNodes::ExprNodes::CallExprCfgNode call |
301304
call = ns.getABindingCall() and
302305
exists(call.getArgument(pos))
303306
)
@@ -306,7 +309,7 @@ private module Cached {
306309
// `ns.getABindingCall()`, but those parameters should still have
307310
// positions since SSA depends on this.
308311
// In particular, global scope is also an uncalled function.
309-
any(Parameter p).getIndexExcludingPipelines() = pos and
312+
any(SsaImpl::NormalParameter p).getIndexExcludingPipelines() = pos and
310313
ns.isEmpty()
311314
} or
312315
TPipelineParameter()

0 commit comments

Comments
 (0)