From 2547a213e3f478ecb4aa7a9c9ad7a6621b84054e Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 9 May 2019 15:06:50 -0700 Subject: [PATCH] Receive Window 1. Fix bug when setting the receive window to 2048 bytes and the LS would fail. The OpenSSH server is splitting a single full names message across mulitple SSH data records. Needed to treat partial reads at the LS level as a would-block. --- src/wolfsftp.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index db44357..066f5bc 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -4730,13 +4730,25 @@ static WS_SFTPNAME* wolfSSH_SFTP_DoName(WOLFSSH* ssh) case SFTP_NAME_GET_PACKET: /* get number of files */ - ret = wolfSSH_stream_read(ssh, state->data, state->sz); - if (ret < 0) { + /* using idx as an offset for partial reads */ + ret = wolfSSH_stream_read(ssh, + state->data + state->idx, state->sz - state->idx); + if (ret <= 0) { if (ssh->error != WS_WANT_READ) { wolfSSH_SFTP_ClearState(ssh, STATE_ID_NAME); } return NULL; } + if ((word32)ret < state->sz - state->idx) { + /* Partial read, treat like a want-read. */ + state->idx += ret; + ssh->error = WS_WANT_READ; + state->state = SFTP_NAME_GET_PACKET; + return NULL; + } + + /* Reset idx back to 0 for parsing the buffer. */ + state->idx = 0; if (state->idx + UINT32_SZ > (word32)state->sz) { ssh->error = WS_BUFFER_E;