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

@ -53,7 +53,7 @@ func NewNS() (ns.NetNS, error) {
nsRunDir := getNsRunDir()
b := make([]byte, 16)
_, err := rand.Reader.Read(b)
_, err := rand.Read(b)
if err != nil {
return nil, fmt.Errorf("failed to generate random netns name: %v", err)
}