From 779c91745045007697d547f3b03e712316877e8a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 13 Sep 2020 23:15:36 +0700 Subject: [PATCH] fix race condition in handshake fuzz code --- fuzzing/handshake/fuzz.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fuzzing/handshake/fuzz.go b/fuzzing/handshake/fuzz.go index 0cd15cc7..3f1e8695 100644 --- a/fuzzing/handshake/fuzz.go +++ b/fuzzing/handshake/fuzz.go @@ -11,6 +11,7 @@ import ( "log" "math" mrand "math/rand" + "sync" "time" "github.com/lucas-clemente/quic-go/fuzzing/internal/helper" @@ -159,6 +160,7 @@ type handshakeRunner interface { } type runner struct { + sync.Mutex errored bool client, server *handshake.CryptoSetup } @@ -172,6 +174,8 @@ func newRunner(client, server *handshake.CryptoSetup) *runner { func (r *runner) OnReceivedParams(*wire.TransportParameters) {} func (r *runner) OnHandshakeComplete() {} func (r *runner) OnError(err error) { + r.Lock() + defer r.Unlock() if r.errored { return } @@ -179,6 +183,11 @@ func (r *runner) OnError(err error) { (*r.client).Close() (*r.server).Close() } +func (r *runner) Errored() bool { + r.Lock() + defer r.Unlock() + return r.errored +} func (r *runner) DropKeys(protocol.EncryptionLevel) {} const alpn = "fuzzing" @@ -435,7 +444,7 @@ messageLoop: case <-done: // test done break messageLoop } - if runner.errored { + if runner.Errored() { break messageLoop } } @@ -443,7 +452,7 @@ messageLoop: <-done _ = client.ConnectionState() _ = server.ConnectionState() - if runner.errored { + if runner.Errored() { return 0 }