mirror of
https://github.com/securego/gosec.git
synced 2024-11-05 19:45:51 +00:00
Backport test case for 1.5
Go 1.5 does not have a rand.Read function so need to adjust test definitions accordingly.
This commit is contained in:
parent
f9868aa8c8
commit
a7ec9ccc63
2 changed files with 8 additions and 6 deletions
|
@ -22,21 +22,23 @@ import (
|
||||||
|
|
||||||
type WeakRand struct {
|
type WeakRand struct {
|
||||||
gas.MetaData
|
gas.MetaData
|
||||||
funcName string
|
funcNames []string
|
||||||
packagePath string
|
packagePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WeakRand) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
|
func (w *WeakRand) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
|
||||||
if _, matched := gas.MatchCallByPackage(n, c, w.packagePath, w.funcName); matched {
|
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 gas.NewIssue(c, n, w.What, w.Severity, w.Confidence), nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWeakRandCheck(conf map[string]interface{}) (gas.Rule, []ast.Node) {
|
func NewWeakRandCheck(conf map[string]interface{}) (gas.Rule, []ast.Node) {
|
||||||
return &WeakRand{
|
return &WeakRand{
|
||||||
funcName: "Read",
|
funcNames: []string{"Read", "Int"},
|
||||||
packagePath: "math/rand",
|
packagePath: "math/rand",
|
||||||
MetaData: gas.MetaData{
|
MetaData: gas.MetaData{
|
||||||
Severity: gas.High,
|
Severity: gas.High,
|
||||||
|
|
|
@ -51,7 +51,7 @@ func TestRandBad(t *testing.T) {
|
||||||
import "math/rand"
|
import "math/rand"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bad, _ := rand.Read(nil)
|
bad := rand.Int()
|
||||||
println(bad)
|
println(bad)
|
||||||
|
|
||||||
}`, analyzer)
|
}`, analyzer)
|
||||||
|
@ -77,7 +77,7 @@ func TestRandRenamed(t *testing.T) {
|
||||||
func main() {
|
func main() {
|
||||||
good, _ := rand.Read(nil)
|
good, _ := rand.Read(nil)
|
||||||
println(good)
|
println(good)
|
||||||
i := mrand.Int()
|
i := mrand.Int31()
|
||||||
println(i)
|
println(i)
|
||||||
}`, analyzer)
|
}`, analyzer)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue