diff --git a/rules/errors.go b/rules/errors.go index 2786426..766521f 100644 --- a/rules/errors.go +++ b/rules/errors.go @@ -89,6 +89,7 @@ func NewNoErrorCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { whitelist.Add("io.PipeWriter", "CloseWithError") whitelist.Add("hash.Hash", "Write") whitelist.Add("os", "Unsetenv") + whitelist.Add("rand", "Read") if configured, ok := conf[id]; ok { if whitelisted, ok := configured.(map[string]interface{}); ok { diff --git a/testutils/g104_samples.go b/testutils/g104_samples.go index fcd8ec8..66b14a5 100644 --- a/testutils/g104_samples.go +++ b/testutils/g104_samples.go @@ -142,6 +142,17 @@ func main() { b := createBuffer() b.WriteString("*bytes.Buffer") } +`}, 0, gosec.NewConfig()}, + {[]string{` +package main + +import "crypto/rand" + +func main() { + b := make([]byte, 8) + rand.Read(b) + _ = b +} `}, 0, gosec.NewConfig()}, } // it shouldn't return any errors because all method calls are whitelisted by default