plugin: avoid using deprecated math/rand.Read

This commit is contained in:
Filippo Valsorda
2025-12-07 21:30:36 +01:00
committed by Filippo Valsorda
parent 96b6476140
commit 83bab2ae6a

View File

@@ -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)