Skip to content

Commit ff5409f

Browse files
authored
Merge pull request github#13785 from owen-mc/go/change-golangSpecificParamArgFilter
Go: Avoid using getTarget() as it may not exist
2 parents 7bc8bf6 + dbc6868 commit ff5409f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowDispatch.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ predicate golangSpecificParamArgFilter(
149149
// Interface methods calls may be passed strictly to that exact method's model receiver:
150150
arg.getPosition() != -1
151151
or
152-
exists(Function callTarget | callTarget = call.getNode().(DataFlow::CallNode).getTarget() |
153-
not isInterfaceMethod(callTarget)
154-
or
155-
callTarget = p.getCallable().asSummarizedCallable().asFunction()
156-
)
152+
p instanceof DataFlow::SummarizedParameterNode
153+
or
154+
not isInterfaceMethod(call.getNode()
155+
.(DataFlow::CallNode)
156+
.getACalleeWithoutVirtualDispatch()
157+
.asFunction())
157158
}

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,9 @@ module Public {
489489
* interface type.
490490
*/
491491
Callable getACalleeIncludingExternals() {
492-
result.asFunction() = this.getTarget()
492+
result = this.getACalleeWithoutVirtualDispatch()
493493
or
494494
exists(DataFlow::Node calleeSource | calleeSource = this.getACalleeSource() |
495-
result.asFuncLit() = calleeSource.asExpr()
496-
or
497-
calleeSource = result.asFunction().getARead()
498-
or
499495
exists(Method declared, Method actual |
500496
calleeSource = declared.getARead() and
501497
actual.implements(declared) and
@@ -510,6 +506,19 @@ module Public {
510506
*/
511507
FuncDef getACallee() { result = this.getACalleeIncludingExternals().getFuncDef() }
512508

509+
/**
510+
* Gets the definition of a possible target of this call, excluding targets reachable via virtual dispatch.
511+
*/
512+
Callable getACalleeWithoutVirtualDispatch() {
513+
result.asFunction() = this.getTarget()
514+
or
515+
exists(DataFlow::Node calleeSource | calleeSource = this.getACalleeSource() |
516+
result.asFuncLit() = calleeSource.asExpr()
517+
or
518+
calleeSource = result.asFunction().getARead()
519+
)
520+
}
521+
513522
/**
514523
* Gets the name of the function, method or variable that is being called.
515524
*

0 commit comments

Comments
 (0)