Skip to content

Commit

Permalink
Merge pull request #2778 from lucas-clemente/fix-handshake-fuzz-race
Browse files Browse the repository at this point in the history
fix race condition in handshake fuzz code
  • Loading branch information
marten-seemann authored Sep 14, 2020
2 parents 8bf5c78 + 779c917 commit 8ad6ef0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fuzzing/handshake/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"math"
mrand "math/rand"
"sync"
"time"

"github.com/lucas-clemente/quic-go/fuzzing/internal/helper"
Expand Down Expand Up @@ -159,6 +160,7 @@ type handshakeRunner interface {
}

type runner struct {
sync.Mutex
errored bool
client, server *handshake.CryptoSetup
}
Expand All @@ -172,13 +174,20 @@ 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
}
r.errored = true
(*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"
Expand Down Expand Up @@ -435,15 +444,15 @@ messageLoop:
case <-done: // test done
break messageLoop
}
if runner.errored {
if runner.Errored() {
break messageLoop
}
}

<-done
_ = client.ConnectionState()
_ = server.ConnectionState()
if runner.errored {
if runner.Errored() {
return 0
}

Expand Down

0 comments on commit 8ad6ef0

Please sign in to comment.