mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-03-04 02:14:40 +01:00
error check all the rand.Read() calls
This commit is contained in:
parent
62ef5c9d02
commit
0f1e3b4ba8
2 changed files with 9 additions and 3 deletions
|
@ -78,7 +78,9 @@ func (proxy *Proxy) Encrypt(
|
||||||
proto string,
|
proto string,
|
||||||
) (sharedKey *[32]byte, encrypted []byte, clientNonce []byte, err error) {
|
) (sharedKey *[32]byte, encrypted []byte, clientNonce []byte, err error) {
|
||||||
nonce, clientNonce := make([]byte, NonceSize), make([]byte, HalfNonceSize)
|
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)
|
copy(nonce, clientNonce)
|
||||||
var publicKey *[PublicKeySize]byte
|
var publicKey *[PublicKeySize]byte
|
||||||
if proxy.ephemeralKeys {
|
if proxy.ephemeralKeys {
|
||||||
|
@ -101,7 +103,9 @@ func (proxy *Proxy) Encrypt(
|
||||||
minQuestionSize = Max(proxy.questionSizeEstimator.MinQuestionSize(), minQuestionSize)
|
minQuestionSize = Max(proxy.questionSizeEstimator.MinQuestionSize(), minQuestionSize)
|
||||||
} else {
|
} else {
|
||||||
var xpad [1]byte
|
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])
|
minQuestionSize += int(xpad[0])
|
||||||
}
|
}
|
||||||
paddedLength := Min(MaxDNSUDPPacketSize, (Max(minQuestionSize, QueryOverhead)+1+63) & ^63)
|
paddedLength := Min(MaxDNSUDPPacketSize, (Max(minQuestionSize, QueryOverhead)+1+63) & ^63)
|
||||||
|
|
|
@ -32,7 +32,9 @@ func main() {
|
||||||
runtime.MemProfileRate = 0
|
runtime.MemProfileRate = 0
|
||||||
|
|
||||||
seed := make([]byte, 8)
|
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[:])))
|
rand.Seed(int64(binary.LittleEndian.Uint64(seed[:])))
|
||||||
|
|
||||||
pwd, err := os.Getwd()
|
pwd, err := os.Getwd()
|
||||||
|
|
Loading…
Add table
Reference in a new issue