From 9ea7d3bcedda3d82f03eb15844cce97f2558539a Mon Sep 17 00:00:00 2001 From: Zhen-Huan HWANG <44398524+zhwang-amad@users.noreply.github.com> Date: Thu, 11 Apr 2019 19:17:18 +0200 Subject: [PATCH] sftp.c : discard and reset oversized packet in sftp_packet_read() (#269) file : sftp.c notes : when sftp_packet_read() encounters an sftp packet which exceeds SFTP max packet size it now resets the reading state so it can continue reading. credit : Zhen-Huan HWANG --- src/sftp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sftp.c b/src/sftp.c index 668bdd47..245f1347 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -346,10 +346,14 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) sftp->partial_len = _libssh2_ntohu32(sftp->partial_size); /* make sure we don't proceed if the packet size is unreasonably large */ - if(sftp->partial_len > LIBSSH2_SFTP_PACKET_MAXLEN) + if(sftp->partial_len > LIBSSH2_SFTP_PACKET_MAXLEN) { + libssh2_channel_flush(channel); + sftp->partial_size_len = 0; return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, "SFTP packet too large"); + } + if(sftp->partial_len == 0) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,