crypto/ssh: fix deadlock during error condition.

Unblock writers if a read error occurs while writers are blocked on a
pending key change.

Add test to check for deadlocks in error paths in handshake.go

Fixes golang/go#11992.

Change-Id: Id098bd9fec3d4fe83daeb2b7f935e5647c19afd3
Reviewed-on: https://go-review.googlesource.com/13594
Reviewed-by: Adam Langley <agl@golang.org>
This commit is contained in:
Han-Wen Nienhuys
2015-08-17 22:20:11 +00:00
committed by Adam Langley
parent 4e213c0672
commit c169681727
2 changed files with 108 additions and 1 deletions
+9 -1
View File
@@ -153,6 +153,14 @@ func (t *handshakeTransport) readLoop() {
}
t.incoming <- p
}
// If we can't read, declare the writing part dead too.
t.mu.Lock()
defer t.mu.Unlock()
if t.writeError == nil {
t.writeError = t.readError
}
t.cond.Broadcast()
}
func (t *handshakeTransport) readOnePacket() ([]byte, error) {
@@ -270,7 +278,7 @@ func (t *handshakeTransport) writePacket(p []byte) error {
if t.writtenSinceKex > t.config.RekeyThreshold {
t.sendKexInitLocked()
}
for t.sentInitMsg != nil {
for t.sentInitMsg != nil && t.writeError == nil {
t.cond.Wait()
}
if t.writeError != nil {