Skip to content

Commit 7b9a41a

Browse files
committed
PS: Handle this parameters in a few more places.
1 parent dcb98ab commit 7b9a41a

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ module Ssa {
113113

114114
override ThisParameter getSourceVariable() { result = v }
115115

116-
final override string toString() { result = "self (" + v.getDeclaringScope() + ")" }
116+
final override string toString() { result = "this (" + v.getDeclaringScope() + ")" }
117117

118118
final override Location getLocation() { result = this.getControlFlowNode().getLocation() }
119119
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ module SsaFlow {
6161

6262
private ParameterNodeImpl toParameterNode(SsaImpl::ParameterExt p) {
6363
result = TNormalParameterNode(p.asParameter())
64+
or
65+
result = TThisParameterNode(p.asThis())
6466
}
6567

6668
Impl::Node asNode(Node n) {
@@ -164,7 +166,6 @@ private module Cached {
164166
cached
165167
newtype TNode =
166168
TExprNode(CfgNodes::ExprCfgNode n) or
167-
TStmtNode(CfgNodes::StmtCfgNode n) or
168169
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or
169170
TNormalParameterNode(SsaImpl::NormalParameter p) or
170171
TThisParameterNode(Method m) or
@@ -549,7 +550,7 @@ private module ParameterNodes {
549550

550551
ThisParameterNode() { this = TThisParameterNode(m) }
551552

552-
override Parameter getParameter() { none() }
553+
override Parameter getParameter() { result = m.getThisParameter() }
553554

554555
override predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
555556
m.getBody() = c.asCfgScope() and

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ module SsaInput implements SsaImplCommon::InputSig<Location> {
2727
*/
2828
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
2929
(
30-
exists(Scope scope | scope = v.(ThisParameter).getDeclaringScope() |
31-
// We consider the `this` variable to have a single write at the entry to a method block
32-
scope = bb.(BasicBlocks::EntryBasicBlock).getScope() and
33-
i = 0
34-
)
35-
or
3630
uninitializedWrite(bb, i, v)
3731
or
3832
variableWriteActual(bb, i, v, _)
@@ -138,9 +132,7 @@ private module Cached {
138132
* AST write access is `write`.
139133
*/
140134
cached
141-
predicate variableWriteActual(
142-
Cfg::BasicBlock bb, int i, Variable v, VarWriteAccessCfgNode write
143-
) {
135+
predicate variableWriteActual(Cfg::BasicBlock bb, int i, Variable v, VarWriteAccessCfgNode write) {
144136
exists(Cfg::CfgNode n |
145137
write.getVariable() = v and
146138
n = bb.getNode(i)
@@ -277,7 +269,8 @@ private Parameter getANonPipelineParameter(FunctionBase f) {
277269
class NormalParameter extends Parameter {
278270
NormalParameter() {
279271
not this instanceof PipelineParameter and
280-
not this instanceof PipelineByPropertyNameParameter
272+
not this instanceof PipelineByPropertyNameParameter and
273+
not this instanceof ThisParameter
281274
}
282275

283276
int getIndexExcludingPipelines() {
@@ -295,18 +288,18 @@ class NormalParameter extends Parameter {
295288

296289
private newtype TParameterExt =
297290
TNormalParameter(NormalParameter p) or
298-
TSelfMethodParameter(Method m)
291+
TThisMethodParameter(Method m)
299292

300-
/** A normal parameter or an implicit `self` parameter. */
293+
/** A normal parameter or an implicit `this` parameter. */
301294
class ParameterExt extends TParameterExt {
302295
NormalParameter asParameter() { this = TNormalParameter(result) }
303296

304-
Method asThis() { this = TSelfMethodParameter(result) }
297+
Method asThis() { this = TThisMethodParameter(result) }
305298

306299
predicate isInitializedBy(WriteDefinition def) {
307300
def = getParameterDef(this.asParameter())
308301
or
309-
def.(Ssa::ThisDefinition).getSourceVariable().getDeclaringScope() = this.asThis().(Scope)
302+
def.(Ssa::ThisDefinition).getSourceVariable().getDeclaringScope() = this.asThis().getBody()
310303
}
311304

312305
string toString() { result = [this.asParameter().toString(), this.asThis().toString()] }

0 commit comments

Comments
 (0)