From 83bab2ae6aecde95dc3bb74599652361c0a8743f Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sun, 7 Dec 2025 21:30:36 +0100 Subject: [PATCH] plugin: avoid using deprecated math/rand.Read --- plugin/client.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugin/client.go b/plugin/client.go index 28ccbf1..cd3a852 100644 --- a/plugin/client.go +++ b/plugin/client.go @@ -8,9 +8,10 @@ package plugin import ( "bufio" + "crypto/rand" "fmt" "io" - "math/rand" + mathrand "math/rand/v2" "os" "path/filepath" "strconv" @@ -468,15 +469,15 @@ func writeStanzaWithBody(conn io.Writer, t string, body []byte) error { } func writeGrease(conn io.Writer) (sent bool, err error) { - if rand.Intn(3) == 0 { + if mathrand.IntN(3) == 0 { return false, nil } - s := &format.Stanza{Type: fmt.Sprintf("grease-%x", rand.Int())} - for i := 0; i < rand.Intn(3); i++ { - s.Args = append(s.Args, fmt.Sprintf("%d", rand.Intn(100))) + s := &format.Stanza{Type: fmt.Sprintf("grease-%x", mathrand.Int())} + for i := 0; i < mathrand.IntN(3); i++ { + s.Args = append(s.Args, fmt.Sprintf("%d", mathrand.IntN(100))) } - if rand.Intn(2) == 0 { - s.Body = make([]byte, rand.Intn(100)) + if mathrand.IntN(2) == 0 { + s.Body = make([]byte, mathrand.IntN(100)) rand.Read(s.Body) } return true, s.Marshal(conn)