mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 21:34:38 +03:00
fix bug with concurrent math/rand.Rand.Read
firstly by using crypto/rand in those cases. and secondly by putting a lock around the Read (though it isn't used at the moment). found while working while implementing sending tls reports.
This commit is contained in:
@ -40,11 +40,19 @@ import (
|
||||
var moxService string
|
||||
|
||||
func pwgen() string {
|
||||
rand := mox.NewRand()
|
||||
chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*-_;:,<.>/"
|
||||
s := ""
|
||||
buf := make([]byte, 1)
|
||||
for i := 0; i < 12; i++ {
|
||||
s += string(chars[rand.Intn(len(chars))])
|
||||
for {
|
||||
cryptorand.Read(buf)
|
||||
i := int(buf[0])
|
||||
if i+len(chars) > 255 {
|
||||
continue // Prevent bias.
|
||||
}
|
||||
s += string(chars[i%len(chars)])
|
||||
break
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
Reference in New Issue
Block a user