error check all the rand.Read() calls

This commit is contained in:
Frank Denis 2023-06-06 09:16:44 +02:00
parent 62ef5c9d02
commit 0f1e3b4ba8
2 changed files with 9 additions and 3 deletions

View File

@ -78,7 +78,9 @@ func (proxy *Proxy) Encrypt(
proto string,
) (sharedKey *[32]byte, encrypted []byte, clientNonce []byte, err error) {
nonce, clientNonce := make([]byte, NonceSize), make([]byte, HalfNonceSize)
crypto_rand.Read(clientNonce)
if _, err := crypto_rand.Read(clientNonce); err != nil {
return nil, nil, nil, err
}
copy(nonce, clientNonce)
var publicKey *[PublicKeySize]byte
if proxy.ephemeralKeys {
@ -101,7 +103,9 @@ func (proxy *Proxy) Encrypt(
minQuestionSize = Max(proxy.questionSizeEstimator.MinQuestionSize(), minQuestionSize)
} else {
var xpad [1]byte
crypto_rand.Read(xpad[:])
if _, err := crypto_rand.Read(xpad[:]); err != nil {
return nil, nil, nil, err
}
minQuestionSize += int(xpad[0])
}
paddedLength := Min(MaxDNSUDPPacketSize, (Max(minQuestionSize, QueryOverhead)+1+63) & ^63)

View File

@ -32,7 +32,9 @@ func main() {
runtime.MemProfileRate = 0
seed := make([]byte, 8)
crypto_rand.Read(seed)
if _, err := crypto_rand.Read(seed); err != nil {
dlog.Fatal(err)
}
rand.Seed(int64(binary.LittleEndian.Uint64(seed[:])))
pwd, err := os.Getwd()