Skip to content

Commit aaa0182

Browse files
committed
PS: Add AST and CFG nodes for operator &.
1 parent 1e1fd45 commit aaa0182

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

powershell/ql/lib/semmle/code/powershell/Command.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import powershell
2+
23
private predicate parseCommandName(Cmd cmd, string namespace, string name) {
34
exists(string qualified | command(cmd, qualified, _, _, _) |
45
namespace = qualified.regexpCapture("([^\\\\]+)\\\\([^\\\\]+)", 1) and
@@ -11,6 +12,7 @@ private predicate parseCommandName(Cmd cmd, string namespace, string name) {
1112
)
1213
}
1314

15+
/** A call to a command. */
1416
class Cmd extends @command, CmdBase {
1517
override string toString() { result = "call to " + this.getQualifiedCommandName() }
1618

@@ -88,3 +90,8 @@ class Cmd extends @command, CmdBase {
8890

8991
Redirection getARedirection() { result = this.getRedirection(_) }
9092
}
93+
94+
/** A call to operator `&`. */
95+
class CallOperator extends Cmd {
96+
CallOperator() { this.getKind() = 28 }
97+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ module StmtNodes {
597597
final override string getName() { result = s.getCmdName().getValue().getValue() }
598598
}
599599

600+
/** A control-flow node that wraps a call to operator `&` */
601+
class CallOperatorCfgNode extends CmdCfgNode {
602+
CallOperatorCfgNode() { this.getStmt() instanceof CallOperator }
603+
}
604+
600605
private class AssignStmtChildMapping extends PipelineBaseChildMapping, AssignStmt {
601606
override predicate relevantChild(Ast n) {
602607
n = this.getLeftHandSide() or n = this.getRightHandSide()

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,30 @@ class CallNode extends AstNode {
448448

449449
Node getQualifier() { result.asExpr() = call.getQualifier() }
450450

451+
/** Gets the i'th argument to this call. */
452+
Node getArgument(int i) { result.asExpr() = call.getArgument(i) }
453+
454+
/** Gets the i'th positional argument to this call. */
455+
Node getPositionalArgument(int i) { result.asExpr() = call.getPositionalArgument(i) }
456+
457+
/** Gets the argument with the name `name`, if any. */
458+
Node getNamedArgument(string name) { result.asExpr() = call.getNamedArgument(name) }
459+
460+
/**
461+
* Gets any argument of this call.
462+
*
463+
* Note that this predicate doesn't get the pipeline argument, if any.
464+
*/
465+
Node getAnArgument() { result.asExpr() = call.getAnArgument() }
466+
451467
int getNumberOfArguments() { result = call.getNumberOfArguments() }
452468
}
453469

470+
/** A call to operator `&`, viwed as a node in a data flow graph. */
471+
class CallOperatorNode extends CallNode {
472+
CallOperatorNode() { this.getCallNode() instanceof CfgNodes::StmtNodes::CallOperatorCfgNode }
473+
}
474+
454475
/** A use of a type name, viewed as a node in a data flow graph. */
455476
class TypeNameNode extends ExprNode {
456477
override CfgNodes::ExprNodes::TypeNameCfgNode n;

0 commit comments

Comments
 (0)