From 8e69d435efb4193e474739674c32ec940c51ddd0 Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Mon, 3 Dec 2018 17:27:08 +0100 Subject: [PATCH] channels: Set error state when closed channel is read When an attempt to read a closed channel happens, set the session error state properly. Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Andreas Schneider --- src/channels.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/channels.c b/src/channels.c index 0dfa946d..8875392a 100644 --- a/src/channels.c +++ b/src/channels.c @@ -2766,8 +2766,13 @@ int ssh_channel_read_timeout(ssh_channel channel, /* * If the channel is closed or in an error state, reading from it is an error */ - if (session->session_state == SSH_SESSION_STATE_ERROR || - channel->state == SSH_CHANNEL_STATE_CLOSED) { + if (session->session_state == SSH_SESSION_STATE_ERROR) { + return SSH_ERROR; + } + if (channel->state == SSH_CHANNEL_STATE_CLOSED) { + ssh_set_error(session, + SSH_FATAL, + "Remote channel is closed."); return SSH_ERROR; } if (channel->remote_eof && ssh_buffer_get_len(stdbuf) == 0) {