Skip to content

Commit c2e24ea

Browse files
committed
PS: Make CFG construction compile again.
1 parent 9efc3ec commit c2e24ea

File tree

5 files changed

+105
-71
lines changed

5 files changed

+105
-71
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ module ExprNodes {
419419

420420
private class IndexExprWriteAccessChildMapping extends IndexExprChildMapping, IndexExprWriteAccess
421421
{
422-
override predicate relevantChild(Ast child) { this.isExplicitWrite(child) }
422+
override predicate relevantChild(Ast child) {
423+
super.relevantChild(child) or
424+
this.isExplicitWrite(child)
425+
}
423426
}
424427

425428
class IndexExprWriteAccessCfgNode extends IndexExprCfgNode {
@@ -443,7 +446,7 @@ module ExprNodes {
443446
}
444447

445448
private class IndexExprReadAccessChildMapping extends IndexExprChildMapping, IndexExprReadAccess {
446-
override predicate relevantChild(Ast child) { none() }
449+
override predicate relevantChild(Ast child) { super.relevantChild(child) }
447450
}
448451

449452
class IndexExprReadAccessCfgNode extends IndexExprCfgNode {
@@ -480,6 +483,8 @@ module ExprNodes {
480483
/** Gets the name that is used to select the callee. */
481484
string getName() { result = e.getName() }
482485

486+
predicate hasName(string name) { this.getName() = name }
487+
483488
/** Gets the i'th positional argument to this call. */
484489
ExprCfgNode getPositionalArgument(int i) {
485490
e.hasCfgChild(e.getPositionalArgument(i), this, result)
@@ -558,7 +563,10 @@ module ExprNodes {
558563
private class MemberExprWriteAccessChildMapping extends MemberExprChildMapping,
559564
MemberExprWriteAccess
560565
{
561-
override predicate relevantChild(Ast child) { this.isExplicitWrite(child) }
566+
override predicate relevantChild(Ast child) {
567+
super.relevantChild(child) or
568+
this.isExplicitWrite(child)
569+
}
562570
}
563571

564572
class MemberExprWriteAccessCfgNode extends MemberExprCfgNode {
@@ -584,7 +592,7 @@ module ExprNodes {
584592
private class MemberExprReadAccessChildMapping extends MemberExprChildMapping,
585593
MemberExprReadAccess
586594
{
587-
override predicate relevantChild(Ast child) { none() }
595+
override predicate relevantChild(Ast child) { super.relevantChild(child) }
588596
}
589597

590598
class MemberExprReadAccessCfgNode extends MemberExprCfgNode {
@@ -1322,9 +1330,7 @@ module StmtNodes {
13221330
}
13231331

13241332
class ConfigurationChildMapping extends NonExprChildMapping, Configuration {
1325-
override predicate relevantChild(Ast child) {
1326-
child = this.getName() or child = this.getBody()
1327-
}
1333+
override predicate relevantChild(Ast child) { child = this.getName() or child = this.getBody() }
13281334
}
13291335

13301336
class ConfigurationCfgNode extends StmtCfgNode {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ private import SuccessorTypes
66
private import internal.ControlFlowGraphImpl as CfgImpl
77
private import internal.Splitting as Splitting
88
private import internal.Completion
9-
private import internal.Scope
109

1110
/**
1211
* An AST node with an associated control-flow graph.
@@ -16,7 +15,16 @@ private import internal.Scope
1615
* Note that module declarations are not themselves CFG scopes, as they are part of
1716
* the CFG of the enclosing top-level or callable.
1817
*/
19-
class CfgScope extends Scope instanceof CfgImpl::CfgScope { }
18+
class CfgScope extends Scope instanceof CfgImpl::CfgScope {
19+
final CfgScope getOuterCfgScope() {
20+
exists(Ast parent |
21+
parent = this.getParent() and
22+
result = CfgImpl::getCfgScope(parent)
23+
)
24+
}
25+
26+
Parameter getAParameter() { result = super.getAParameter() }
27+
}
2028

2129
/**
2230
* A control flow node.

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ private newtype TCompletion =
2222
TMatchingCompletion(Boolean b) or
2323
TEmptinessCompletion(Boolean isEmpty)
2424

25-
private predicate commandThrows(Cmd c, boolean unconditional) {
26-
c.getNamedArgument("ErrorAction").(StringConstExpr).getValue().getValue() = "Stop" and
27-
if c.getCommandName() = "Write-Error" then unconditional = true else unconditional = false
25+
private predicate commandThrows(CallExpr c, boolean unconditional) {
26+
c.getNamedArgument("ErrorAction").getValue().asString() = "Stop" and
27+
if c.getName() = "Write-Error" then unconditional = true else unconditional = false
2828
}
2929

3030
pragma[noinline]
@@ -127,7 +127,7 @@ private predicate mustHaveMatchingCompletion(Ast n) { inMatchingContext(n) }
127127
* that `n` evaluates to determines a true/false branch successor.
128128
*/
129129
private predicate inBooleanContext(Ast n) {
130-
n = any(IfStmt ifStmt).getACondition()
130+
n = any(If ifStmt).getACondition()
131131
or
132132
n = any(WhileStmt whileStmt).getCondition()
133133
or
@@ -165,10 +165,7 @@ private predicate inBooleanContext(Ast n) {
165165
n = pipeline.getComponent(pipeline.getNumberOfComponents() - 1)
166166
)
167167
or
168-
exists(CmdExpr cmdExpr |
169-
inBooleanContext(cmdExpr) and
170-
n = cmdExpr.getExpr()
171-
)
168+
n = any(ParenExpr parent | inBooleanContext(parent)).getExpr()
172169
}
173170

174171
/**

0 commit comments

Comments
 (0)