From: Jason A. Donenfeld Date: Thu, 17 Oct 2019 13:43:06 +0000 (+0200) Subject: device: recheck counters while holding write lock X-Git-Tag: 0.0.20200121~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae492d1b359918d20fda817e31675f126c7a7837;p=thirdparty%2Fwireguard-go.git device: recheck counters while holding write lock --- diff --git a/device/noise-protocol.go b/device/noise-protocol.go index dd75cc3..88c6aae 100644 --- a/device/noise-protocol.go +++ b/device/noise-protocol.go @@ -315,8 +315,13 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer { handshake.chainKey = chainKey handshake.remoteIndex = msg.Sender handshake.remoteEphemeral = msg.Ephemeral - handshake.lastTimestamp = timestamp - handshake.lastInitiationConsumption = time.Now() + if timestamp.After(handshake.lastTimestamp) { + handshake.lastTimestamp = timestamp + } + now := time.Now() + if now.After(handshake.lastInitiationConsumption) { + handshake.lastInitiationConsumption = now + } handshake.state = HandshakeInitiationConsumed handshake.mutex.Unlock()