Use crypto/rand.Read, not crypto.Reader.Read

The current code accidentally ignores partial reads, since it doesn't
check the return value of (io.Reader).Read.

What we actually want is io.ReadFull(rand.Reader, buf), which is
conveniently provided by rand.Read(buf).

Signed-off-by: edef <edef@edef.eu>
This commit is contained in:
edef
2021-09-17 13:20:15 +00:00
parent a6b5412c55
commit 90c018566c
2 changed files with 2 additions and 2 deletions

View File

@ -107,7 +107,7 @@ func makeVeth(name, vethPeerName string, mtu int, mac string, hostNS ns.NetNS) (
// RandomVethName returns string "veth" with random prefix (hashed from entropy)
func RandomVethName() (string, error) {
entropy := make([]byte, 4)
_, err := rand.Reader.Read(entropy)
_, err := rand.Read(entropy)
if err != nil {
return "", fmt.Errorf("failed to generate random veth name: %v", err)
}