]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rand: fix race on r.used
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 6 May 2022 14:50:19 +0000 (16:50 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 6 May 2022 17:41:30 +0000 (17:41 +0000)
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>

src/crypto/rand/rand_unix.go

index 64b865289d99fba7673a82e8bfb1dd70795ae019..830983c74ac65c42c5467722fad38b5fa25d3839 100644 (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()