mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-26 01:03:15 +03:00
sftp: Fix incorrect handling of received length fields
Signed-off-by: Tilo Eckert <tilo.eckert@flam.de>
This commit is contained in:
committed by
Aris Adamantiadis
parent
dc9c4d22ab
commit
672c3be9ed
12
src/sftp.c
12
src/sftp.c
@@ -307,7 +307,7 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
|
||||
sftp_packet packet = NULL;
|
||||
uint32_t tmp;
|
||||
size_t size;
|
||||
int r;
|
||||
int r, s;
|
||||
|
||||
packet = malloc(sizeof(struct sftp_packet_struct));
|
||||
if (packet == NULL) {
|
||||
@@ -322,12 +322,18 @@ sftp_packet sftp_packet_read(sftp_session sftp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r=ssh_channel_read(sftp->channel, buffer, 4, 0);
|
||||
if (r < 0) {
|
||||
r=0;
|
||||
do {
|
||||
// read from channel until 4 bytes have been read or an error occurs
|
||||
s=ssh_channel_read(sftp->channel, buffer+r, 4-r, 0);
|
||||
if (s < 0) {
|
||||
ssh_buffer_free(packet->payload);
|
||||
SAFE_FREE(packet);
|
||||
return NULL;
|
||||
} else {
|
||||
r += s;
|
||||
}
|
||||
} while (r<4);
|
||||
ssh_buffer_add_data(packet->payload, buffer, r);
|
||||
if (buffer_get_u32(packet->payload, &tmp) != sizeof(uint32_t)) {
|
||||
ssh_set_error(sftp->session, SSH_FATAL, "Short sftp packet!");
|
||||
|
||||
Reference in New Issue
Block a user