mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
sftp: fix handling unexpected EOF in sftp_packet_read()
If the server failed to serve the promised amount of data, `sftp_packet_read()` could be stuck in a loop, prior to this patch. Report-and-patch-by: RELAUNCH DEPT. Fixes GHSA-2q3j-q544-xxp7 Closes #2581
This commit is contained in:
16
src/sftp.c
16
src/sftp.c
@@ -289,6 +289,12 @@ static int sftp_packet_read(LIBSSH2_SFTP *sftp)
|
||||
return (int)rc;
|
||||
else if(rc < 0)
|
||||
return ssh2_err(session, (int)rc, "channel read");
|
||||
else if(rc == 0) {
|
||||
sftp->packet_header_len = 0;
|
||||
return ssh2_err(session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"Unexpected channel EOF while reading "
|
||||
"SFTP packet header");
|
||||
}
|
||||
|
||||
sftp->packet_header_len += rc;
|
||||
|
||||
@@ -381,11 +387,15 @@ window_adjust:
|
||||
sftp->packet_state = ssh2_NB_state_sent1;
|
||||
return (int)rc;
|
||||
}
|
||||
else if(rc < 0) {
|
||||
else if(rc <= 0) {
|
||||
SSH2_FREE(session, packet);
|
||||
sftp->partial_packet = NULL;
|
||||
return ssh2_err(session, (int)rc,
|
||||
"Error waiting for SFTP packet");
|
||||
if(rc < 0)
|
||||
return ssh2_err(session, (int)rc,
|
||||
"Error waiting for SFTP packet");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"Unexpected channel EOF while reading "
|
||||
"SFTP packet body");
|
||||
}
|
||||
sftp->partial_received += rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user