From d78a29eb792fd09c836dd5f5db7f29c1c449ec2a Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Mon, 3 Dec 2018 17:25:22 +0100 Subject: [PATCH] sftp: Set error when EOF is received in sftp_packet_read() When reading a sftp packet and an EOF is received before all requested bytes are read, set the session and sftp error codes. Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Andreas Schneider --- src/sftp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sftp.c b/src/sftp.c index b4ddedcd..c4cd0e16 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -396,6 +396,10 @@ sftp_packet sftp_packet_read(sftp_session sftp) } else if (s == 0) { is_eof = ssh_channel_is_eof(sftp->channel); if (is_eof) { + ssh_set_error(sftp->session, + SSH_FATAL, + "Received EOF while reading sftp packet size"); + sftp_set_error(sftp, SSH_FX_EOF); goto error; } } else { @@ -416,6 +420,10 @@ sftp_packet sftp_packet_read(sftp_session sftp) } else if (nread == 0) { is_eof = ssh_channel_is_eof(sftp->channel); if (is_eof) { + ssh_set_error(sftp->session, + SSH_FATAL, + "Received EOF while reading sftp packet type"); + sftp_set_error(sftp, SSH_FX_EOF); goto error; } } @@ -451,6 +459,10 @@ sftp_packet sftp_packet_read(sftp_session sftp) /* Retry the reading unless the remote was closed */ is_eof = ssh_channel_is_eof(sftp->channel); if (is_eof) { + ssh_set_error(sftp->session, + SSH_REQUEST_DENIED, + "Received EOF while reading sftp packet"); + sftp_set_error(sftp, SSH_FX_EOF); goto error; } }