Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,29 @@ module ExprNodes {

InvokeMemberCfgNode getInvokeMember() { this = result.getQualifier() }
}

class ConditionalChildMapping extends ExprChildMapping, ConditionalExpr {
override predicate relevantChild(Ast n) { n = this.getCondition() or n = this.getABranch() }
}

/** A control-flow node that wraps a `ConditionalExpr` expression. */
class ConditionalCfgNode extends ExprCfgNode {
override string getAPrimaryQlClass() { result = "ConditionalCfgNode" }

override ConditionalChildMapping e;

final override ConditionalExpr getExpr() { result = super.getExpr() }

final ExprCfgNode getCondition() { e.hasCfgChild(e.getCondition(), this, result) }

final ExprCfgNode getBranch(boolean value) { e.hasCfgChild(e.getBranch(value), this, result) }

final ExprCfgNode getABranch() { result = this.getBranch(_) }

final ExprCfgNode getIfTrue() { e.hasCfgChild(e.getIfTrue(), this, result) }

final ExprCfgNode getIfFalse() { e.hasCfgChild(e.getIfFalse(), this, result) }
}
}

module StmtNodes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ module SsaFlow {
module LocalFlow {
pragma[nomagic]
predicate localFlowStepCommon(Node nodeFrom, Node nodeTo) {
none() // TODO
nodeFrom.asExpr() = nodeTo.asExpr().(CfgNodes::ExprNodes::ConditionalCfgNode).getABranch()
or
nodeFrom.asStmt() = nodeTo.asStmt().(CfgNodes::StmtNodes::AssignStmtCfgNode).getRightHandSide()
}

predicate localMustFlowStep(Node node1, Node node2) { none() }
predicate localMustFlowStep(Node nodeFrom, Node nodeTo) {
nodeFrom.asStmt() = nodeTo.asStmt().(CfgNodes::StmtNodes::AssignStmtCfgNode).getRightHandSide()
}
}

/** Provides logic related to captured variables. */
Expand Down Expand Up @@ -125,11 +129,22 @@ private module Cached {
* data flow.
*/
cached
predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo, string model) { none() }
predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo, string model) {
(
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
or
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
) and
model = ""
}

/** This is the local flow predicate that is exposed. */
cached
predicate localFlowStepImpl(Node nodeFrom, Node nodeTo) { none() }
predicate localFlowStepImpl(Node nodeFrom, Node nodeTo) {
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
or
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
}

cached
newtype TContentSet = TSingletonContent(Content c)
Expand Down