From 90c018566c4b6014129e221553ed5e26d8766c91 Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 17 Sep 2021 13:20:15 +0000 Subject: [PATCH] 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 --- pkg/ip/link_linux.go | 2 +- pkg/testutils/netns_linux.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ip/link_linux.go b/pkg/ip/link_linux.go index 94e14f228..9e6f17c69 100644 --- a/pkg/ip/link_linux.go +++ b/pkg/ip/link_linux.go @@ -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) } diff --git a/pkg/testutils/netns_linux.go b/pkg/testutils/netns_linux.go index f009bfb0a..b9683a3a4 100644 --- a/pkg/testutils/netns_linux.go +++ b/pkg/testutils/netns_linux.go @@ -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) }