Skip to content

Commit dcb98ab

Browse files
committed
PS: Don't include the this parameter in getParameter.
1 parent cea435c commit dcb98ab

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class ScriptBlock extends Ast, TScriptBlock {
7979
result = this.getParameter(index)
8080
)
8181
or
82+
i = ThisVar() and
83+
result = this.getThisParameter()
84+
or
8285
exists(int index |
8386
i = scriptBlockUsing(index) and
8487
result = this.getUsingStmt(index)
@@ -90,13 +93,14 @@ class ScriptBlock extends Ast, TScriptBlock {
9093
or
9194
any(Synthesis s).pipelineParameterHasIndex(this, i) and
9295
synthChild(getRawAst(this), PipelineParamVar(), result)
93-
or
94-
i = -1 and
95-
synthChild(getRawAst(this), ThisVar(), result)
9696
}
9797

98+
Parameter getThisParameter() { synthChild(getRawAst(this), ThisVar(), result) }
99+
98100
/**
99101
* Gets a parameter of this block.
102+
*
103+
* Note: This does not include the `this` parameter, but it does include pipeline parameters.
100104
*/
101105
Parameter getAParameter() { result = this.getParameter(_) }
102106

powershell/ql/lib/semmle/code/powershell/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ module Trees {
151151

152152
override predicate succ(AstNode pred, AstNode succ, Completion c) {
153153
this.succEntry(pred, c) and
154+
(
155+
first(super.getThisParameter(), succ)
156+
or
157+
not exists(super.getThisParameter()) and
158+
first(super.getParameter(0), succ)
159+
or
160+
not exists(super.getThisParameter()) and
161+
not exists(super.getAParameter()) and
162+
first(super.getBeginBlock(), succ)
163+
or
164+
not exists(super.getThisParameter()) and
165+
not exists(super.getAParameter()) and
166+
not exists(super.getBeginBlock()) and
167+
first(super.getProcessBlock(), succ)
168+
or
169+
not exists(super.getThisParameter()) and
170+
not exists(super.getAParameter()) and
171+
not exists(super.getBeginBlock()) and
172+
not exists(super.getProcessBlock()) and
173+
first(super.getEndBlock(), succ)
174+
)
175+
or
176+
last(super.getThisParameter(), pred, c) and
177+
completionIsNormal(c) and
154178
(
155179
first(super.getParameter(0), succ)
156180
or

0 commit comments

Comments
 (0)