mirror of
https://github.com/securego/gosec.git
synced 2026-01-15 01:33:41 +08:00
whitelist crypto/rand Read from error checks (#1446)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user