From 34f6b9425588ddc44be3645e674e6c2312fda417 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 16 Apr 2021 16:03:57 +0200 Subject: [PATCH] gosec: G404: Use of weak random number generator These should be ok to ignore for the purpose they're used pkg/namesgenerator/names-generator.go:843:36: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec) name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))]) ^ pkg/namesgenerator/names-generator.go:849:36: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec) name = fmt.Sprintf("%s%d", name, rand.Intn(10)) ^ testutil/stringutils.go:11:18: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec) b[i] = letters[rand.Intn(len(letters))] ^ pkg/namesgenerator/names-generator.go:849:36: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec) name = fmt.Sprintf("%s%d", name, rand.Intn(10)) ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 6b0ecacd921cefbed1d79466b88080620b17e5ed) Signed-off-by: Sebastiaan van Stijn --- pkg/namesgenerator/names-generator.go | 4 ++-- testutil/stringutils.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/namesgenerator/names-generator.go b/pkg/namesgenerator/names-generator.go index 2dfb66af03..716af687e1 100644 --- a/pkg/namesgenerator/names-generator.go +++ b/pkg/namesgenerator/names-generator.go @@ -840,13 +840,13 @@ var ( // integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3` func GetRandomName(retry int) string { begin: - name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))]) + name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))]) //nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) if name == "boring_wozniak" /* Steve Wozniak is not boring */ { goto begin } if retry > 0 { - name = fmt.Sprintf("%s%d", name, rand.Intn(10)) + name = fmt.Sprintf("%s%d", name, rand.Intn(10)) //nolint:gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) } return name } diff --git a/testutil/stringutils.go b/testutil/stringutils.go index 62092faa36..885ebe560b 100644 --- a/testutil/stringutils.go +++ b/testutil/stringutils.go @@ -8,7 +8,7 @@ func GenerateRandomAlphaOnlyString(n int) string { letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") b := make([]byte, n) for i := range b { - b[i] = letters[rand.Intn(len(letters))] + b[i] = letters[rand.Intn(len(letters))] //nolint: gosec // G404: Use of weak random number generator (math/rand instead of crypto/rand) } return string(b) }