Skip to content

Commit b054093

Browse files
committed
PS: Resolve non-member function calls using the dataflow's lambda call resolution features.
1 parent f6a5b4b commit b054093

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -597,22 +597,25 @@ predicate isUnreachableInCall(NodeRegion nr, DataFlowCall call) { none() }
597597

598598
newtype LambdaCallKind = TLambdaCallKind()
599599

600-
/** Holds if `creation` is an expression that creates a lambda of kind `kind` for `c`. */
601-
predicate lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c) { none() }
600+
private class CmdName extends StringConstExpr {
601+
CmdName() { this = any(Cmd c).getCmdName() }
602602

603-
/**
604-
* Holds if `call` is a from-source lambda call of kind `kind` where `receiver`
605-
* is the lambda expression.
606-
*/
607-
predicate lambdaSourceCall(CfgNodes::StmtNodes::CmdCfgNode call, LambdaCallKind kind, Node receiver) {
608-
none()
603+
string getName() { result = this.getValue().getValue() }
604+
}
605+
606+
/** Holds if `creation` is an expression that creates a lambda of kind `kind` for `c`. */
607+
predicate lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c) {
608+
creation.asExpr().getExpr().(CmdName).getName() = c.asCfgScope().getEnclosingFunction().getName() and
609+
exists(kind)
609610
}
610611

611612
/**
612613
* Holds if `call` is a (from-source or from-summary) lambda call of kind `kind`
613614
* where `receiver` is the lambda expression.
614615
*/
615-
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) { none() }
616+
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
617+
call.asCall().getCommand() = receiver.asExpr() and exists(kind)
618+
}
616619

617620
/** Extra data-flow steps needed for lambda flow analysis. */
618621
predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preservesValue) { none() }

0 commit comments

Comments
 (0)