From: Jason A. Donenfeld Date: Fri, 6 May 2022 14:50:19 +0000 (+0200) Subject: crypto/rand: fix race on r.used X-Git-Tag: go1.19beta1~376 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=091e913414794d9176861b1ffcdbcfdc2d742af3;p=gostls13.git 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 --- 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()