From 7de155af646f59ba221d44d0f989a0f03fd09206 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Sun, 4 Jun 2023 16:14:32 +0200 Subject: [PATCH] [golangci-lint]: Use stronger random number generator for rPad. --- helpers.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/helpers.go b/helpers.go index bda4e58..9c0508a 100644 --- a/helpers.go +++ b/helpers.go @@ -6,9 +6,10 @@ package main import ( "bytes" + "crypto/rand" "fmt" "log" - "math/rand" + "math/big" "net/url" "os" "regexp" @@ -50,9 +51,14 @@ func readFile(path string) (*bytes.Buffer, error) { func getRpad(messageLength int) string { rpadRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") length := 100 - messageLength%100 + max := big.NewInt(int64(len(rpadRunes))) rpad := make([]rune, length) for i := range rpad { - rpad[i] = rpadRunes[rand.Intn(len(rpadRunes))] + randInt, err := rand.Int(rand.Reader, max) + if err != nil { + log.Fatal(err) + } + rpad[i] = rpadRunes[randInt.Int64()] } return string(rpad) }