1
0
mirror of https://github.com/golang/go synced 2024-11-23 23:20:08 -07:00

crypto/rand: fix race on r.used

This race is benign, but it still trips up the race detector, so turn
this into an atomic read.

Fixes #52739.

Change-Id: Ib53362286b456513c8c69d6d2d73c6c90ec095f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/404475
Auto-Submit: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2022-05-06 16:50:19 +02:00 committed by Gopher Robot
parent 2049649e8b
commit 091e913414

View File

@ -59,7 +59,7 @@ func (r *reader) Read(b []byte) (n int, err error) {
}
if atomic.LoadUint32(&r.used) != 2 {
r.mu.Lock()
if r.used != 2 {
if atomic.LoadUint32(&r.used) != 2 {
f, err := os.Open(urandomDevice)
if err != nil {
r.mu.Unlock()