From 373017ab9d33606ce6d7cc9d56e8cf4e03aae335 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 13 Apr 2022 16:51:34 +0100 Subject: [PATCH] Add tests for callees through function variables --- .../semmle/go/dataflow/CallGraph/getACallee.expected | 2 ++ .../semmle/go/dataflow/CallGraph/test.go | 12 +++++++++++- .../go/dataflow/CallGraph/viableCallee.expected | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.expected b/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.expected index e256662850c..66521f0258a 100644 --- a/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.expected +++ b/ql/test/library-tests/semmle/go/dataflow/CallGraph/getACallee.expected @@ -1,6 +1,8 @@ missingCallee +| test.go:58:2:58:8 | call to f | test.go:41:1:53:1 | function declaration | spuriousCallee | main.go:44:3:44:7 | call to m | main.go:17:1:17:17 | function declaration | | main.go:44:3:44:7 | call to m | main.go:21:1:21:20 | function declaration | | main.go:56:2:56:6 | call to m | main.go:21:1:21:20 | function declaration | | test.go:42:2:42:13 | call to Write | test.go:36:1:39:1 | function declaration | +| test.go:44:2:44:8 | call to f1 | test.go:36:1:39:1 | function declaration | diff --git a/ql/test/library-tests/semmle/go/dataflow/CallGraph/test.go b/ql/test/library-tests/semmle/go/dataflow/CallGraph/test.go index 61c85502afa..cbd7a40cc58 100644 --- a/ql/test/library-tests/semmle/go/dataflow/CallGraph/test.go +++ b/ql/test/library-tests/semmle/go/dataflow/CallGraph/test.go @@ -40,10 +40,20 @@ func (_ MockWriter) Write(p []byte) (n int, err error) { // name: MockWriter.Wri func test5(h hash.Hash, w io.Writer) { // name: test5 h.Write(nil) // callee: MockHash.Write + f1 := h.Write + f1(nil) // callee: MockHash.Write + w.Write(nil) // callee: MockWriter.Write callee: MockHash.Write - h.Reset() // callee: Resetter.Reset + f2 := w.Write + f2(nil) // callee: MockWriter.Write callee: MockHash.Write + + h.Reset() // callee: Resetter.Reset + f3 := h.Reset + f3() // callee: Resetter.Reset } func test6(h MockHash, w MockWriter) { test5(h, w) // callee: test5 + f := test5 + f(h, w) // callee: test5 } diff --git a/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.expected b/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.expected index 381d576a20b..458751a0fd3 100644 --- a/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.expected +++ b/ql/test/library-tests/semmle/go/dataflow/CallGraph/viableCallee.expected @@ -1,2 +1,7 @@ missingCallee +| test.go:44:2:44:8 | call to f1 | test.go:17:1:20:1 | function declaration | +| test.go:48:2:48:8 | call to f2 | test.go:17:1:20:1 | function declaration | +| test.go:48:2:48:8 | call to f2 | test.go:36:1:39:1 | function declaration | +| test.go:52:2:52:5 | call to f3 | test.go:11:1:11:28 | function declaration | +| test.go:58:2:58:8 | call to f | test.go:41:1:53:1 | function declaration | spuriousCallee