Skip to content

Commit 830bf57

Browse files
committed
PS: Pipeline parameter and argument positions.
1 parent cbf9496 commit 830bf57

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ module ExprNodes {
213213
override VarAccessChildMapping e;
214214

215215
override VarAccess getExpr() { result = super.getExpr() }
216+
217+
Variable getVariable() { result = e.getVariable() }
216218
}
217219

218220
private class VarReadAccessChildMapping extends VarAccessChildMapping, VarReadAccess { }
@@ -234,8 +236,6 @@ module ExprNodes {
234236

235237
override VarWriteAccess getExpr() { result = super.getExpr() }
236238

237-
Variable getVariable() { result = e.getVariable() }
238-
239239
predicate isExplicitWrite(StmtNodes::AssignStmtCfgNode assignment) {
240240
this = assignment.getLeftHandSide()
241241
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ private module Cached {
229229
call = ns.getABindingCall() and
230230
exists(call.getArgument(pos))
231231
)
232-
}
232+
} or
233+
TPipelineArgumentPosition()
233234

234235
cached
235236
newtype TParameterPosition =
@@ -240,7 +241,8 @@ private module Cached {
240241
call = ns.getABindingCall() and
241242
exists(call.getArgument(pos))
242243
)
243-
}
244+
} or
245+
TPipelineParameter()
244246
}
245247

246248
import Cached
@@ -259,6 +261,8 @@ class ParameterPosition extends TParameterPosition {
259261
/** Holds if this parameter is a keyword parameter with `name`. */
260262
predicate isKeyword(string name) { this = TKeywordParameter(name) }
261263

264+
predicate isPipeline() { this = TPipelineParameter() }
265+
262266
/** Gets a textual representation of this position. */
263267
string toString() {
264268
this.isThis() and result = "this"
@@ -268,6 +272,8 @@ class ParameterPosition extends TParameterPosition {
268272
)
269273
or
270274
exists(string name | this.isKeyword(name) and result = "kw(" + name + ")")
275+
or
276+
this.isPipeline() and result = "pipeline"
271277
}
272278
}
273279

@@ -281,6 +287,8 @@ class ArgumentPosition extends TArgumentPosition {
281287

282288
predicate isKeyword(string name) { this = TKeywordArgumentPosition(name) }
283289

290+
predicate isPipeline() { this = TPipelineArgumentPosition() }
291+
284292
/** Gets a textual representation of this position. */
285293
string toString() {
286294
this.isThis() and result = "this"
@@ -290,6 +298,8 @@ class ArgumentPosition extends TArgumentPosition {
290298
)
291299
or
292300
exists(string name | this.isKeyword(name) and result = "kw(" + name + ")")
301+
or
302+
this.isPipeline() and result = "pipeline"
293303
}
294304
}
295305

@@ -307,4 +317,6 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
307317
ppos.isPositional(pos, ns) and
308318
apos.isPositional(pos, ns)
309319
)
320+
or
321+
ppos.isPipeline() and apos.isPipeline()
310322
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,18 @@ private module ParameterNodes {
449449
// keywords in S are specified.
450450
exists(int i, int j, string name, NamedSet ns, Function f |
451451
pos.isPositional(j, ns) and
452-
parameter.getIndex() = i and
452+
parameter.getIndexExcludingPipeline() = i and
453453
f = parameter.getFunction() and
454454
f = ns.getAFunction() and
455455
name = parameter.getName() and
456456
not name = ns.getAName() and
457-
j = i - count(int k | k < i and f.getParameter(k).getName() = ns.getAName())
457+
j =
458+
i -
459+
count(int k, Parameter p |
460+
k < i and
461+
p = f.getParameterExcludingPipline(k) and
462+
p.getName() = ns.getAName()
463+
)
458464
)
459465
)
460466
}

0 commit comments

Comments
 (0)