mirror of
https://github.com/securego/gosec.git
synced 2024-11-05 19:45:51 +00:00
Fix the call list info to handle selector expressions
Signed-off-by: Cosmin Cojocar <cosmin.cojocar@gmx.ch>
This commit is contained in:
parent
cf2590442c
commit
7da9f46445
3 changed files with 26 additions and 1 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue