Skip to content

Commit ebc7327

Browse files
committed
PS: Get rid of the pipelineVARIABLE and only have pipelinePARAMETER (and similarly for the by-propertyname versions).
1 parent 16348b5 commit ebc7327

File tree

5 files changed

+51
-47
lines changed

5 files changed

+51
-47
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/Parameter.qll

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,49 @@ class Parameter extends Variable instanceof ParameterImpl {
3434

3535
class ThisParameter extends Parameter instanceof ThisParameterImpl { }
3636

37-
class PipelineParameter extends Parameter {
38-
PipelineParameter() { any(Synthesis s).isPipelineParameter(this) }
37+
/** The pipeline parameter of a function. */
38+
class PipelineParameter extends Parameter instanceof PipelineParameterImpl {
39+
ScriptBlock getScriptBlock() { result = super.getScriptBlock() }
3940
}
4041

41-
class PipelineByPropertyNameParameter extends Parameter {
42-
PipelineByPropertyNameParameter() {
43-
exists(NamedAttributeArgument namedAttribute |
44-
this.getAnAttribute().(Attribute).getANamedArgument() = namedAttribute and
45-
namedAttribute.getName().toLowerCase() = "valuefrompipelinebypropertyname"
46-
|
47-
namedAttribute.getValue().getValue().asBoolean() = true
48-
or
49-
not exists(namedAttribute.getValue().getValue().asBoolean())
50-
)
51-
}
42+
/**
43+
* The iterator variable associated with a pipeline parameter.
44+
*
45+
* This is the variable that is bound to the current element in the pipeline.
46+
*/
47+
class PipelineIteratorVariable extends Variable instanceof PipelineIteratorVariableImpl {
48+
ProcessBlock getProcessBlock() { result = super.getProcessBlock() }
49+
}
50+
51+
/**
52+
* A pipeline-by-property-name parameter of a function.
53+
*/
54+
class PipelineByPropertyNameParameter extends Parameter instanceof PipelineByPropertyNameParameterImpl
55+
{
56+
ScriptBlock getScriptBlock() { result = super.getScriptBlock() }
5257

53-
string getPropertyName() { result = this.getName() }
58+
string getPropertyName() { result = super.getName() }
5459

60+
/**
61+
* Gets the iterator variable that is used to iterate over the elements in the pipeline.
62+
*/
5563
PipelineByPropertyNameIteratorVariable getIteratorVariable() { result.getParameter() = this }
5664
}
65+
66+
/**
67+
* The iterator variable associated with a pipeline-by-property-name parameter.
68+
*
69+
* This is the variable that is bound to the current element in the pipeline.
70+
*/
71+
class PipelineByPropertyNameIteratorVariable extends Variable instanceof PipelineByPropertyNameIteratorVariableImpl
72+
{
73+
ProcessBlock getProcessBlock() { result = super.getProcessBlock() }
74+
75+
string getPropertyName() { result = super.getPropertyName() }
76+
77+
/**
78+
* Gets the pipeline-by-property-name parameter that this variable
79+
* iterates over.
80+
*/
81+
PipelineByPropertyNameParameter getParameter() { result = super.getParameter() }
82+
}

powershell/ql/lib/semmle/code/powershell/ast/internal/Synthesis.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,12 +871,12 @@ private module PipelineAccess {
871871
final override predicate child(Raw::Ast parent, ChildIndex i, Child child) {
872872
exists(Raw::ProcessBlock pb | parent = pb |
873873
i = processBlockPipelineVarReadAccess() and
874-
exists(PipelineVariable pipelineVar |
875-
pipelineVar = TVariableSynth(pb.getScriptBlock(), PipelineParamVar()) and
874+
exists(PipelineParameter pipelineVar |
875+
pipelineVar = getPipelineParameter(pb.getScriptBlock()) and
876876
child = SynthChild(VarAccessSynthKind(pipelineVar))
877877
)
878878
or
879-
exists(PipelineByPropertyNameVariable pipelineVar, Raw::PipelineByPropertyNameParameter p |
879+
exists(PipelineByPropertyNameParameter pipelineVar, Raw::PipelineByPropertyNameParameter p |
880880
i = processBlockPipelineByPropertyNameVarReadAccess(p.getName()) and
881881
getResultAst(p) = pipelineVar and
882882
child = SynthChild(VarAccessSynthKind(pipelineVar))

powershell/ql/lib/semmle/code/powershell/ast/internal/Variable.qll

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ module Private {
5454
override ThisVar i;
5555
}
5656

57-
class PipelineVariableImpl extends ParameterImpl {
57+
class PipelineParameterImpl extends ParameterImpl {
5858
override FunParam i;
5959

60-
PipelineVariableImpl() {
60+
PipelineParameterImpl() {
6161
exists(int index |
6262
i = FunParam(index) and
6363
any(Synthesis s).pipelineParameterHasIndex(super.getDeclaringScopeImpl(), index)
@@ -67,8 +67,8 @@ module Private {
6767
ScriptBlock getScriptBlock() { this = TVariableSynth(getRawAst(result), _) }
6868
}
6969

70-
class PipelineByPropertyNameVariableImpl extends ParameterImpl {
71-
PipelineByPropertyNameVariableImpl() {
70+
class PipelineByPropertyNameParameterImpl extends ParameterImpl {
71+
PipelineByPropertyNameParameterImpl() {
7272
getRawAst(this) instanceof Raw::PipelineByPropertyNameParameter
7373
}
7474

@@ -173,28 +173,6 @@ module Public {
173173
class VarReadAccess extends VarAccess {
174174
VarReadAccess() { not this instanceof VarWriteAccess }
175175
}
176-
177-
class PipelineByPropertyNameIteratorVariable extends Variable instanceof PipelineByPropertyNameIteratorVariableImpl
178-
{
179-
ProcessBlock getProcessBlock() { result = super.getProcessBlock() }
180-
181-
string getPropertyName() { result = super.getPropertyName() }
182-
183-
PipelineByPropertyNameParameter getParameter() { result = super.getParameter() }
184-
}
185-
186-
class PipelineVariable extends Variable instanceof PipelineVariableImpl {
187-
ScriptBlock getScriptBlock() { result = super.getScriptBlock() }
188-
}
189-
190-
class PipelineByPropertyNameVariable extends Variable instanceof PipelineByPropertyNameVariableImpl
191-
{
192-
ScriptBlock getScriptBlock() { result = super.getScriptBlock() }
193-
}
194-
195-
class PipelineIteratorVariable extends Variable instanceof PipelineIteratorVariableImpl {
196-
ProcessBlock getProcessBlock() { result = super.getProcessBlock() }
197-
}
198176
}
199177

200178
import Public

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ class ProcessBlockCfgNode extends NamedBlockCfgNode {
291291

292292
ScriptBlockCfgNode getScriptBlock() { result.getProcessBlock() = this }
293293

294-
PipelineVariable getPipelineVariable() {
294+
PipelineParameter getPipelineParameter() {
295295
result.getScriptBlock() = this.getScriptBlock().getAstNode()
296296
}
297297

298-
ExprNodes::VarReadAccessCfgNode getPipelineVariableAccess() {
298+
ExprNodes::VarReadAccessCfgNode getPipelineParameterAccess() {
299299
block.hasCfgChild(block.getPipelineParameterAccess(), this, result)
300300
}
301301

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module LocalFlow {
164164
nodeTo = TProcessPropertyByNameNode(pbNode.getAccess().getVariable(), false)
165165
)
166166
or
167-
nodeTo.(PreProcessNode).getProcessBlock().getPipelineVariableAccess() = nodeFrom.asExpr()
167+
nodeTo.(PreProcessNode).getProcessBlock().getPipelineParameterAccess() = nodeFrom.asExpr()
168168
or
169169
nodeTo.(ProcessNode).getProcessBlock() = nodeFrom.(PreProcessNode).getProcessBlock()
170170
}
@@ -1010,7 +1010,7 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
10101010
or
10111011
c.isAnyPositional() and
10121012
exists(CfgNodes::ProcessBlockCfgNode processBlock |
1013-
processBlock.getPipelineVariableAccess() = node1.asExpr() and
1013+
processBlock.getPipelineParameterAccess() = node1.asExpr() and
10141014
node2 = TProcessNode(processBlock)
10151015
)
10161016
or

0 commit comments

Comments
 (0)