From 2da8da0777d6370adee01fbb7528c1796112532d Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Fri, 28 Mar 2025 19:30:16 +0000 Subject: [PATCH] PS: Add helper predicates for if statements. --- .../ql/lib/semmle/code/powershell/ast/internal/If.qll | 8 ++++++++ .../semmle/code/powershell/controlflow/CfgNodes.qll | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll b/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll index 94192397060..4aa44a2359d 100644 --- a/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll +++ b/powershell/ql/lib/semmle/code/powershell/ast/internal/If.qll @@ -53,5 +53,13 @@ class If extends Expr, TIf { ) } + StmtBlock getABranch(boolean b) { + b = true and result = this.getAThen() + or + b = false and result = this.getElse() + } + + StmtBlock getABranch() { result = this.getAThen() or result = this.getElse() } + predicate hasElse() { exists(this.getElse()) } } diff --git a/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll b/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll index 438ef698afe..ac3faab7c13 100644 --- a/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll +++ b/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll @@ -900,6 +900,16 @@ module ExprNodes { StmtCfgNode getAThen() { result = this.getThen(_) } StmtCfgNode getElse() { e.hasCfgChild(e.getElse(), this, result) } + + StmtCfgNode getABranch(boolean b) { + b = true and + result = this.getAThen() + or + b = false and + result = this.getElse() + } + + StmtCfgNode getABranch() { result = this.getABranch(_) } } private class LiteralChildMapping extends ExprChildMapping, Literal {