From a1ce240cfbdb72802ae523dd8e15fee99d4e1b90 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 10 Mar 2019 19:24:01 +0000 Subject: [PATCH] ssh2bpp: try to report DISCONNECT before connection closure. There was a race between toplevel callbacks: if we read enough data to receive an SSH_MSG_DISCONNECT, and then returned, then whether we reported the DISCONNECT message or the followup EOF would depend on whether the BPP or the master PPL got called back first. Now the BPP politely waits its turn (i.e. waits to see if it even gets called back at all) before reporting EOF. --- ssh2bpp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ssh2bpp.c b/ssh2bpp.c index befcfdf7..8b8ccc43 100644 --- a/ssh2bpp.c +++ b/ssh2bpp.c @@ -645,6 +645,13 @@ static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp) } eof: + /* + * We've seen EOF. But we might have pushed stuff on the outgoing + * packet queue first, and that stuff _might_ include a DISCONNECT + * message, in which case we'd like to use that as the diagnostic. + * So first wait for the queue to have been processed. + */ + crMaybeWaitUntilV(!pq_peek(&s->bpp.in_pq)); if (!s->bpp.expect_close) { ssh_remote_error(s->bpp.ssh, "Remote side unexpectedly closed network connection");