Merge pull request #13785 from owen-mc/go/change-golangSpecificParamArgFilter

Go: Avoid using getTarget() as it may not exist
This commit is contained in:
Owen Mansel-Chan
2023-08-02 15:40:40 +01:00
committed by GitHub
2 changed files with 20 additions and 10 deletions

View File

@@ -149,9 +149,10 @@ predicate golangSpecificParamArgFilter(
// Interface methods calls may be passed strictly to that exact method's model receiver:
arg.getPosition() != -1
or
exists(Function callTarget | callTarget = call.getNode().(DataFlow::CallNode).getTarget() |
not isInterfaceMethod(callTarget)
or
callTarget = p.getCallable().asSummarizedCallable().asFunction()
)
p instanceof DataFlow::SummarizedParameterNode
or
not isInterfaceMethod(call.getNode()
.(DataFlow::CallNode)
.getACalleeWithoutVirtualDispatch()
.asFunction())
}

View File

@@ -489,13 +489,9 @@ module Public {
* interface type.
*/
Callable getACalleeIncludingExternals() {
result.asFunction() = this.getTarget()
result = this.getACalleeWithoutVirtualDispatch()
or
exists(DataFlow::Node calleeSource | calleeSource = this.getACalleeSource() |
result.asFuncLit() = calleeSource.asExpr()
or
calleeSource = result.asFunction().getARead()
or
exists(Method declared, Method actual |
calleeSource = declared.getARead() and
actual.implements(declared) and
@@ -510,6 +506,19 @@ module Public {
*/
FuncDef getACallee() { result = this.getACalleeIncludingExternals().getFuncDef() }
/**
* Gets the definition of a possible target of this call, excluding targets reachable via virtual dispatch.
*/
Callable getACalleeWithoutVirtualDispatch() {
result.asFunction() = this.getTarget()
or
exists(DataFlow::Node calleeSource | calleeSource = this.getACalleeSource() |
result.asFuncLit() = calleeSource.asExpr()
or
calleeSource = result.asFunction().getARead()
)
}
/**
* Gets the name of the function, method or variable that is being called.
*