diff --git a/powershell/ql/lib/semmle/code/powershell/Command.qll b/powershell/ql/lib/semmle/code/powershell/Command.qll index 76528163d42..c8fd5f14859 100644 --- a/powershell/ql/lib/semmle/code/powershell/Command.qll +++ b/powershell/ql/lib/semmle/code/powershell/Command.qll @@ -1,4 +1,5 @@ import powershell + private predicate parseCommandName(Cmd cmd, string namespace, string name) { exists(string qualified | command(cmd, qualified, _, _, _) | namespace = qualified.regexpCapture("([^\\\\]+)\\\\([^\\\\]+)", 1) and @@ -11,6 +12,7 @@ private predicate parseCommandName(Cmd cmd, string namespace, string name) { ) } +/** A call to a command. */ class Cmd extends @command, CmdBase { override string toString() { result = "call to " + this.getQualifiedCommandName() } @@ -88,3 +90,8 @@ class Cmd extends @command, CmdBase { Redirection getARedirection() { result = this.getRedirection(_) } } + +/** A call to operator `&`. */ +class CallOperator extends Cmd { + CallOperator() { this.getKind() = 28 } +} diff --git a/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll b/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll index a55fa3f680a..27e43029dee 100644 --- a/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll +++ b/powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll @@ -597,6 +597,11 @@ module StmtNodes { final override string getName() { result = s.getCmdName().getValue().getValue() } } + /** A control-flow node that wraps a call to operator `&` */ + class CallOperatorCfgNode extends CmdCfgNode { + CallOperatorCfgNode() { this.getStmt() instanceof CallOperator } + } + private class AssignStmtChildMapping extends PipelineBaseChildMapping, AssignStmt { override predicate relevantChild(Ast n) { n = this.getLeftHandSide() or n = this.getRightHandSide() diff --git a/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPublic.qll b/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPublic.qll index 8394a704558..63e3eaab755 100644 --- a/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPublic.qll +++ b/powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPublic.qll @@ -448,9 +448,30 @@ class CallNode extends AstNode { Node getQualifier() { result.asExpr() = call.getQualifier() } + /** Gets the i'th argument to this call. */ + Node getArgument(int i) { result.asExpr() = call.getArgument(i) } + + /** Gets the i'th positional argument to this call. */ + Node getPositionalArgument(int i) { result.asExpr() = call.getPositionalArgument(i) } + + /** Gets the argument with the name `name`, if any. */ + Node getNamedArgument(string name) { result.asExpr() = call.getNamedArgument(name) } + + /** + * Gets any argument of this call. + * + * Note that this predicate doesn't get the pipeline argument, if any. + */ + Node getAnArgument() { result.asExpr() = call.getAnArgument() } + int getNumberOfArguments() { result = call.getNumberOfArguments() } } +/** A call to operator `&`, viwed as a node in a data flow graph. */ +class CallOperatorNode extends CallNode { + CallOperatorNode() { this.getCallNode() instanceof CfgNodes::StmtNodes::CallOperatorCfgNode } +} + /** A use of a type name, viewed as a node in a data flow graph. */ class TypeNameNode extends ExprNode { override CfgNodes::ExprNodes::TypeNameCfgNode n;