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:
committed by
Adam Langley
parent
4e213c0672
commit
c169681727
+9
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user