diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-12-10 14:12:34 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-12-10 17:50:22 +0100 |
commit | 32221ea9fbfcb762e081bc49c9f47290b5a30c4f (patch) | |
tree | c730d403a2e1fe86903c1e9f8feaae1b331c95f6 | |
parent | 917ba07478457793d1239ded124786a9d88e8754 (diff) | |
download | libssh-32221ea9fbfcb762e081bc49c9f47290b5a30c4f.tar.gz libssh-32221ea9fbfcb762e081bc49c9f47290b5a30c4f.tar.xz libssh-32221ea9fbfcb762e081bc49c9f47290b5a30c4f.zip |
channels: Send close if we received a remote close
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit c3067f8e73244ae1268ee45b373dee7183216b67)
-rw-r--r-- | src/channels.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/channels.c b/src/channels.c index 4d00378e..0c0bd44c 100644 --- a/src/channels.c +++ b/src/channels.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <errno.h> #include <time.h> +#include <stdbool.h> #ifndef _WIN32 #include <netinet/in.h> @@ -1008,8 +1009,29 @@ void ssh_channel_free(ssh_channel channel) } session = channel->session; - if (session->alive && channel->state == SSH_CHANNEL_STATE_OPEN) { - ssh_channel_close(channel); + if (session->alive) { + bool send_close = false; + + switch (channel->state) { + case SSH_CHANNEL_STATE_OPEN: + send_close = true; + break; + case SSH_CHANNEL_STATE_CLOSED: + if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) { + send_close = true; + } + if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_LOCAL) { + send_close = false; + } + break; + default: + send_close = false; + break; + } + + if (send_close) { + ssh_channel_close(channel); + } } channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL; |