Skip to content

Commit 075633a

Browse files
authored
Merge pull request github#13780 from github/revert-13767-go/missing-flow-through-receiver
Revert "Go: Fix missing flow through receiver for function variable"
2 parents 6f5d58c + 374f13e commit 075633a

File tree

16 files changed

+42
-79
lines changed

16 files changed

+42
-79
lines changed

go/ql/lib/change-notes/2023-07-19-method-call-node.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

go/ql/lib/semmle/go/controlflow/IR.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ module IR {
744744

745745
override Type getResultType() {
746746
exists(CallExpr c | this.getBase() = evalExprInstruction(c) |
747-
result = c.getCalleeType().getResultType(i)
747+
result = c.getTarget().getResultType(i)
748748
)
749749
or
750750
exists(Expr e | this.getBase() = evalExprInstruction(e) |

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private import DataFlowPrivate
88
private predicate isInterfaceCallReceiver(
99
DataFlow::CallNode call, DataFlow::Node recv, InterfaceType tp, string m
1010
) {
11-
call.(DataFlow::MethodCallNode).getReceiver() = recv and
11+
call.getReceiver() = recv and
1212
recv.getType().getUnderlyingType() = tp and
1313
m = call.getACalleeIncludingExternals().asFunction().getName()
1414
}
@@ -149,9 +149,7 @@ 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 |
153-
callTarget = call.getNode().(DataFlow::CallNode).getACalleeIncludingExternals().asFunction()
154-
|
152+
exists(Function callTarget | callTarget = call.getNode().(DataFlow::CallNode).getTarget() |
155153
not isInterfaceMethod(callTarget)
156154
or
157155
callTarget = p.getCallable().asSummarizedCallable().asFunction()

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

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ module Public {
439439
CallNode getCallNode() { result = call }
440440

441441
override Type getType() {
442-
exists(SignatureType t | t = call.getCall().getCalleeType() |
443-
result = t.getParameterType(t.getNumParameter() - 1)
442+
exists(Function f | f = call.getTarget() |
443+
result = f.getParameterType(f.getNumParameter() - 1)
444444
)
445445
}
446446

@@ -474,11 +474,7 @@ module Public {
474474
class CallNode extends ExprNode {
475475
override CallExpr expr;
476476

477-
/**
478-
* Gets the declared target of this call, if it exists.
479-
*
480-
* This doesn't exist when a function is called via a variable.
481-
*/
477+
/** Gets the declared target of this call */
482478
Function getTarget() { result = expr.getTarget() }
483479

484480
private DataFlow::Node getACalleeSource() { result = getACalleeSource(this) }
@@ -626,40 +622,16 @@ module Public {
626622
/** Gets a result of this call. */
627623
Node getAResult() { result = this.getResult(_) }
628624

629-
/**
630-
* Gets the data flow node corresponding to the receiver of this call, if any.
631-
*
632-
* When a method value is assigned to a variable then when it is called it
633-
* looks like a function call, as in the following example.
634-
* ```go
635-
* file, _ := os.Open("test.txt")
636-
* f := file.Close
637-
* f()
638-
* ```
639-
* In this case we use local flow to try to find the receiver (`file` in
640-
* the above example).
641-
*/
625+
/** Gets the data flow node corresponding to the receiver of this call, if any. */
642626
Node getReceiver() { result = this.getACalleeSource().(MethodReadNode).getReceiver() }
643627

644628
/** Holds if this call has an ellipsis after its last argument. */
645629
predicate hasEllipsis() { expr.hasEllipsis() }
646630
}
647631

648-
/**
649-
* A data flow node that represents a call to a method.
650-
*
651-
* When a method value is assigned to a variable then when it is called it
652-
* syntactically looks like a function call, as in the following example.
653-
* ```go
654-
* file, _ := os.Open("test.txt")
655-
* f := file.Close
656-
* f()
657-
* ```
658-
* In this case we use local flow to see whether a method is assigned to the
659-
* function.
660-
*/
632+
/** A data flow node that represents a call to a method. */
661633
class MethodCallNode extends CallNode {
662-
MethodCallNode() { getACalleeSource(this) instanceof MethodReadNode }
634+
MethodCallNode() { expr.getTarget() instanceof Method }
663635

664636
override Method getTarget() { result = expr.getTarget() }
665637

go/ql/lib/semmle/go/frameworks/Gqlgen.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Gqlgen {
77
/** An autogenerated file containing gqlgen code. */
88
private class GqlgenGeneratedFile extends File {
99
GqlgenGeneratedFile() {
10-
exists(DataFlow::MethodCallNode call |
10+
exists(DataFlow::CallNode call |
1111
call.getReceiver().getType().hasQualifiedName("github.com/99designs/gqlgen/graphql", _) and
1212
call.getFile() = this
1313
)

go/ql/lib/semmle/go/frameworks/stdlib/NetHttp.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ module NetHttp {
131131
)
132132
or
133133
stack = SummaryComponentStack::argument(-1) and
134-
result = call.(DataFlow::MethodCallNode).getReceiver()
134+
result = call.getReceiver()
135135
}
136136

137137
private class ResponseBody extends Http::ResponseBody::Range {

go/ql/lib/semmle/go/security/ExternalAPIs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ExternalApiDataNode extends DataFlow::Node {
8686
this = call.getArgument(i)
8787
or
8888
// Receiver to a call to a method which returns non trivial value
89-
this = call.(DataFlow::MethodCallNode).getReceiver() and
89+
this = call.getReceiver() and
9090
i = -1
9191
) and
9292
// Not defined in the code that is being analyzed

go/ql/lib/semmle/go/security/SafeUrlFlowCustomizations.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ module SafeUrlFlow {
3333

3434
/** A function model step using `UnsafeUrlMethod`, considered as a sanitizer for safe URL flow. */
3535
private class UnsafeUrlMethodEdge extends SanitizerEdge {
36-
UnsafeUrlMethodEdge() {
37-
this = any(UnsafeUrlMethod um).getACall().(DataFlow::MethodCallNode).getReceiver()
38-
}
36+
UnsafeUrlMethodEdge() { this = any(UnsafeUrlMethod um).getACall().getReceiver() }
3937
}
4038

4139
/** Any slicing of the URL, considered as a sanitizer for safe URL flow. */

go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ predicate isWritableFileHandle(DataFlow::Node source, DataFlow::CallNode call) {
9090
/**
9191
* Holds if `os.File.Close` is called on `sink`.
9292
*/
93-
predicate isCloseSink(DataFlow::Node sink, DataFlow::MethodCallNode closeCall) {
93+
predicate isCloseSink(DataFlow::Node sink, DataFlow::CallNode closeCall) {
9494
// find calls to the os.File.Close function
9595
closeCall = any(CloseFileFun f).getACall() and
9696
// that are unhandled
@@ -115,7 +115,7 @@ predicate isCloseSink(DataFlow::Node sink, DataFlow::MethodCallNode closeCall) {
115115
* Holds if `os.File.Sync` is called on `sink` and the result of the call is neither
116116
* deferred nor discarded.
117117
*/
118-
predicate isHandledSync(DataFlow::Node sink, DataFlow::MethodCallNode syncCall) {
118+
predicate isHandledSync(DataFlow::Node sink, DataFlow::CallNode syncCall) {
119119
// find a call of the `os.File.Sync` function
120120
syncCall = any(SyncFileFun f).getACall() and
121121
// match the sink with the object on which the method is called

go/ql/src/Security/CWE-352/ConstantOauth2State.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class PrivateUrlFlowsToAuthCodeUrlCall extends DataFlow::Configuration {
113113
)
114114
}
115115

116-
predicate isSinkCall(DataFlow::Node sink, DataFlow::MethodCallNode call) {
116+
predicate isSinkCall(DataFlow::Node sink, DataFlow::CallNode call) {
117117
exists(AuthCodeUrl m | call = m.getACall() | sink = call.getReceiver())
118118
}
119119

0 commit comments

Comments
 (0)