diff --git a/call_list_test.go b/call_list_test.go index 99f3b8d..c2f5301 100644 --- a/call_list_test.go +++ b/call_list_test.go @@ -99,7 +99,7 @@ var _ = Describe("Call List", func() { // Create file to be scanned pkg := testutils.NewTestPackage() defer pkg.Close() - pkg.AddFile("main.go", testutils.SampleCodeG104[5].Code[0]) + pkg.AddFile("main.go", testutils.SampleCodeG104[6].Code[0]) ctx := pkg.CreateContext("main.go") diff --git a/helpers.go b/helpers.go index 473ddef..40dc8e9 100644 --- a/helpers.go +++ b/helpers.go @@ -135,6 +135,14 @@ func GetCallInfo(n ast.Node, ctx *Context) (string, string, error) { return "undefined", fn.Sel.Name, fmt.Errorf("missing type info") } return expr.Name, fn.Sel.Name, nil + case *ast.SelectorExpr: + if expr.Sel != nil { + t := ctx.Info.TypeOf(expr.Sel) + if t != nil { + return t.String(), fn.Sel.Name, nil + } + return "undefined", fn.Sel.Name, fmt.Errorf("missing type info") + } case *ast.CallExpr: switch call := expr.Fun.(type) { case *ast.Ident: diff --git a/testutils/source.go b/testutils/source.go index ad6a93b..38a843f 100644 --- a/testutils/source.go +++ b/testutils/source.go @@ -234,6 +234,23 @@ package main func dummy(){} `}, 0, gosec.NewConfig()}, {[]string{` package main + +import ( + "bytes" +) + +type a struct { + buf *bytes.Buffer +} + +func main() { + a := &a{ + buf: new(bytes.Buffer), + } + a.buf.Write([]byte{0}) +} +`}, 0, gosec.NewConfig()}, {[]string{` +package main import ( "io/ioutil" "os"