mirror of
https://github.com/rclone/rclone
synced 2024-11-25 02:47:14 +01:00
build: remove random.Seed since random generator is seeded automatically in go1.20
Now that the minimum version is go1.20 we can stop seeding the random number generator.
This commit is contained in:
parent
13fb2fb2ec
commit
938b43c26c
@ -39,7 +39,6 @@ import (
|
||||
"github.com/rclone/rclone/lib/atexit"
|
||||
"github.com/rclone/rclone/lib/buildinfo"
|
||||
"github.com/rclone/rclone/lib/exitcode"
|
||||
"github.com/rclone/rclone/lib/random"
|
||||
"github.com/rclone/rclone/lib/terminal"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
@ -562,9 +561,6 @@ func AddBackendFlags() {
|
||||
|
||||
// Main runs rclone interpreting flags and commands out of os.Args
|
||||
func Main() {
|
||||
if err := random.Seed(); err != nil {
|
||||
log.Fatalf("Fatal error: %v", err)
|
||||
}
|
||||
setupRootCommand(Root)
|
||||
AddBackendFlags()
|
||||
if err := Root.Execute(); err != nil {
|
||||
|
@ -49,11 +49,6 @@ var (
|
||||
MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}$`)
|
||||
)
|
||||
|
||||
// Seed the random number generator
|
||||
func init() {
|
||||
_ = random.Seed()
|
||||
}
|
||||
|
||||
// Initialise rclone for testing
|
||||
func Initialise() {
|
||||
ctx := context.Background()
|
||||
|
@ -1,17 +0,0 @@
|
||||
//go:build go1.20
|
||||
|
||||
package random
|
||||
|
||||
// Seed the global math/rand with crypto strong data
|
||||
//
|
||||
// This doesn't make it OK to use math/rand in crypto sensitive
|
||||
// environments - don't do that! However it does help to mitigate the
|
||||
// problem if that happens accidentally. This would have helped with
|
||||
// CVE-2020-28924 - #4783
|
||||
//
|
||||
// As of Go 1.20 there is no reason to call math/rand.Seed with a
|
||||
// random value as it is self seeded to a random 64 bit number so this
|
||||
// does nothing.
|
||||
func Seed() error {
|
||||
return nil
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//go:build !go1.20
|
||||
|
||||
package random
|
||||
|
||||
import (
|
||||
cryptorand "crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
mathrand "math/rand"
|
||||
)
|
||||
|
||||
// Seed the global math/rand with crypto strong data
|
||||
//
|
||||
// This doesn't make it OK to use math/rand in crypto sensitive
|
||||
// environments - don't do that! However it does help to mitigate the
|
||||
// problem if that happens accidentally. This would have helped with
|
||||
// CVE-2020-28924 - #4783
|
||||
//
|
||||
// As of Go 1.20 there is no reason to call math/rand.Seed with a
|
||||
// random value as it is self seeded to a random 64 bit number.
|
||||
func Seed() error {
|
||||
var seed int64
|
||||
err := binary.Read(cryptorand.Reader, binary.LittleEndian, &seed)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read random seed: %w", err)
|
||||
}
|
||||
mathrand.Seed(seed)
|
||||
return nil
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package random
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -49,16 +48,3 @@ func TestPasswordDuplicates(t *testing.T) {
|
||||
seen[s] = true
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeed(t *testing.T) {
|
||||
// seed 100 times and check the first random number doesn't repeat
|
||||
// This test could fail with a probability of ~ 10**-15
|
||||
const n = 100
|
||||
var seen = map[int64]bool{}
|
||||
for i := 0; i < n; i++ {
|
||||
assert.NoError(t, Seed())
|
||||
first := rand.Int63()
|
||||
assert.False(t, seen[first])
|
||||
seen[first] = true
|
||||
}
|
||||
}
|
||||
|
@ -29,12 +29,6 @@ var (
|
||||
testNumber atomic.Int32
|
||||
)
|
||||
|
||||
// Seed the random number generator
|
||||
func init() {
|
||||
_ = random.Seed()
|
||||
|
||||
}
|
||||
|
||||
// Test contains stats about the running test which work for files or
|
||||
// directories
|
||||
type Test struct {
|
||||
|
Loading…
Reference in New Issue
Block a user