diff --git a/rules/rand.go b/rules/rand.go index 47ac55d..9cc99e4 100644 --- a/rules/rand.go +++ b/rules/rand.go @@ -22,13 +22,15 @@ import ( type WeakRand struct { gas.MetaData - funcName string + funcNames []string packagePath string } func (w *WeakRand) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) { - if _, matched := gas.MatchCallByPackage(n, c, w.packagePath, w.funcName); matched { - return gas.NewIssue(c, n, w.What, w.Severity, w.Confidence), nil + for _, funcName := range w.funcNames { + if _, matched := gas.MatchCallByPackage(n, c, w.packagePath, funcName); matched { + return gas.NewIssue(c, n, w.What, w.Severity, w.Confidence), nil + } } return nil, nil @@ -36,7 +38,7 @@ func (w *WeakRand) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) { func NewWeakRandCheck(conf map[string]interface{}) (gas.Rule, []ast.Node) { return &WeakRand{ - funcName: "Read", + funcNames: []string{"Read", "Int"}, packagePath: "math/rand", MetaData: gas.MetaData{ Severity: gas.High, diff --git a/rules/rand_test.go b/rules/rand_test.go index b1b547a..d6de104 100644 --- a/rules/rand_test.go +++ b/rules/rand_test.go @@ -51,7 +51,7 @@ func TestRandBad(t *testing.T) { import "math/rand" func main() { - bad, _ := rand.Read(nil) + bad := rand.Int() println(bad) }`, analyzer) @@ -77,7 +77,7 @@ func TestRandRenamed(t *testing.T) { func main() { good, _ := rand.Read(nil) println(good) - i := mrand.Int() + i := mrand.Int31() println(i) }`, analyzer)