From 091e913414794d9176861b1ffcdbcfdc2d742af3 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 6 May 2022 16:50:19 +0200 Subject: [PATCH] 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 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills Run-TryBot: Jason Donenfeld --- src/crypto/rand/rand_unix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/rand/rand_unix.go b/src/crypto/rand/rand_unix.go index 64b865289d..830983c74a 100644 --- a/src/crypto/rand/rand_unix.go +++ b/src/crypto/rand/rand_unix.go @@ -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() -- 2.50.0