Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

build: remove random.Seed since random generator is seeded automatically in go1.20

Nick Craig-Wood938b43c26cc2
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 7043995f0..784d785e9 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -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 {
diff --git a/fstest/fstest.go b/fstest/fstest.go
index eebdcbd33..c74ae6e9a 100644
--- a/fstest/fstest.go
+++ b/fstest/fstest.go
@@ -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()
diff --git a/lib/random/random_seed.go b/lib/random/random_seed.go
deleted file mode 100644
index c0c165779..000000000
--- a/lib/random/random_seed.go
+++ /dev/null
@@ -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
-}
diff --git a/lib/random/random_seed_old.go b/lib/random/random_seed_old.go
deleted file mode 100644
index 8fce03ec3..000000000
--- a/lib/random/random_seed_old.go
+++ /dev/null
@@ -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
-}
diff --git a/lib/random/random_test.go b/lib/random/random_test.go
index a710833d3..1be57dda6 100644
--- a/lib/random/random_test.go
+++ b/lib/random/random_test.go
@@ -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
- }
-}
diff --git a/vfs/test_vfs/test_vfs.go b/vfs/test_vfs/test_vfs.go
index 3e70ce1cb..4725a7bd7 100644
--- a/vfs/test_vfs/test_vfs.go
+++ b/vfs/test_vfs/test_vfs.go
@@ -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 {