mirror of
https://github.com/securego/gosec.git
synced 2025-01-11 20:35:52 +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
|
// Create file to be scanned
|
||||||
pkg := testutils.NewTestPackage()
|
pkg := testutils.NewTestPackage()
|
||||||
defer pkg.Close()
|
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")
|
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 "undefined", fn.Sel.Name, fmt.Errorf("missing type info")
|
||||||
}
|
}
|
||||||
return expr.Name, fn.Sel.Name, nil
|
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:
|
case *ast.CallExpr:
|
||||||
switch call := expr.Fun.(type) {
|
switch call := expr.Fun.(type) {
|
||||||
case *ast.Ident:
|
case *ast.Ident:
|
||||||
|
|
|
@ -234,6 +234,23 @@ package main
|
||||||
func dummy(){}
|
func dummy(){}
|
||||||
`}, 0, gosec.NewConfig()}, {[]string{`
|
`}, 0, gosec.NewConfig()}, {[]string{`
|
||||||
package main
|
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 (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
Loading…
Reference in a new issue