Skip to content

Commit 3d18175

Browse files
committed
PS: Make it possible to specify a named argument that must be present in MaD.
1 parent 43de3a1 commit 3d18175

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ module API {
152152
pragma[inline_late]
153153
Node getReturn() { Impl::returnEdge(this.getAnEpsilonSuccessor(), result) }
154154

155+
/**
156+
* Gets the result of this call when there is a named argument with the
157+
* name `name`, or the return value of this callable.
158+
*/
159+
bindingset[this]
160+
pragma[inline_late]
161+
Node getReturnWithArg(string name) {
162+
Impl::returnEdgeWithArg(this.getAnEpsilonSuccessor(), name, result)
163+
}
164+
155165
/**
156166
* Gets the result of a call to `method` with this value as the receiver, or the return value of `method` defined on
157167
* an object that can reach this sink.
@@ -695,6 +705,21 @@ module API {
695705
)
696706
}
697707

708+
cached
709+
predicate returnEdgeWithArg(Node pred, string arg, Node succ) {
710+
exists(DataFlow::CallNode call |
711+
pred = MkMethodAccessNode(call) and
712+
exists(call.getNamedArgument(arg)) and
713+
succ = getForwardStartNode(call)
714+
)
715+
or
716+
arg = "" and // TODO
717+
exists(DataFlow::CallableNode callable |
718+
pred = getBackwardEndNode(callable) and
719+
succ = MkSinkNode(callable.getAReturnNode())
720+
)
721+
}
722+
698723
cached
699724
predicate entryPointEdge(EntryPoint entry, Node node) {
700725
node = MkSinkNode(entry.getASink()) or

powershell/ql/lib/semmle/code/powershell/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ API::Node getSuccessorFromNode(API::Node node, AccessPathTokenBase token) {
254254
result = node.getParameter(parseIntUnbounded(token.getAnArgument()))
255255
or
256256
token.getName() = "ReturnValue" and
257-
result = node.getReturn()
257+
(
258+
not exists(token.getAnArgument()) and
259+
result = node.getReturn()
260+
or
261+
result = node.getReturnWithArg(token.getAnArgument())
262+
)
258263
or
259264
// Language-specific tokens
260265
result = Specific::getExtraSuccessorFromNode(node, token)
@@ -269,7 +274,12 @@ API::Node getSuccessorFromInvoke(Specific::InvokeNode invoke, AccessPathTokenBas
269274
result = invoke.getParameter(parseIntWithArity(token.getAnArgument(), invoke.getNumArgument()))
270275
or
271276
token.getName() = "ReturnValue" and
272-
result = invoke.getReturn()
277+
(
278+
not exists(token.getAnArgument()) and
279+
result = invoke.getReturn()
280+
or
281+
result = invoke.getReturnWithArg(token.getAnArgument())
282+
)
273283
or
274284
// Language-specific tokens
275285
result = Specific::getExtraSuccessorFromInvoke(invoke, token)

powershell/ql/lib/semmle/code/powershell/frameworks/data/internal/ApiGraphModelsSpecific.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ API::Node getExtraNodeFromType(string rawType) {
9595
result = qualifiedTypeName.(DataFlow::LocalSourceNode).track().getInstance()
9696
)
9797
or
98-
(rawType = ["", getAnImplicitImport()]) and
98+
rawType = ["", getAnImplicitImport()] and
9999
result = API::root()
100100
}
101101

0 commit comments

Comments
 (0)