summaryrefslogtreecommitdiffhomepage
path: root/pkg/rand
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-03-18 02:14:59 +0000
committergVisor bot <gvisor-bot@google.com>2020-03-18 02:14:59 +0000
commitbf6c168bd699b9852797af6a49964e87a9c78b50 (patch)
tree00b2f39818d308e978b7d8456694accf1f82ba9f /pkg/rand
parentf8a4f78c24842d9c65c0b3dc927404921acdd559 (diff)
parenteddd6ce514e3bbcc08ce9d8435c7dac12715989c (diff)
Merge release-20200219.0-189-geddd6ce (automated)
Diffstat (limited to 'pkg/rand')
-rw-r--r--pkg/rand/rand_linux.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/pkg/rand/rand_linux.go b/pkg/rand/rand_linux.go
index 0bdad5fad..1aec96e2b 100644
--- a/pkg/rand/rand_linux.go
+++ b/pkg/rand/rand_linux.go
@@ -45,12 +45,18 @@ func (r *reader) Read(p []byte) (int, error) {
return rand.Read(p)
}
+// mu protects the global Reader below.
+var mu sync.Mutex
+
// Reader is the default reader.
var Reader io.Reader = &reader{}
// Read reads from the default reader.
func Read(b []byte) (int, error) {
- return io.ReadFull(Reader, b)
+ mu.Lock()
+ n, err := io.ReadFull(Reader, b)
+ mu.Unlock()
+ return n, err
}
// Init can be called to make sure /dev/urandom is pre-opened on kernels that