Merge pull request #430 from JacobBarthelmeh/sftp

SFTP want write and SSH quick rekey issues
pull/432/head
David Garske 2022-07-14 13:07:07 -07:00 committed by GitHub
commit 1d1ac2c475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 4 deletions

View File

@ -1137,8 +1137,15 @@ static int sftp_worker(thread_ctx_t* threadCtx)
if (threadCtx->nonBlock) {
if (error == WS_WANT_READ)
printf("... sftp server would read block\n");
else if (error == WS_WANT_WRITE)
else if (error == WS_WANT_WRITE) {
word32 c;
printf("... sftp server would write block\n");
/* handle backlog of send packets */
wolfSSH_worker(threadCtx->ssh, &c);
ret = error = wolfSSH_get_error(threadCtx->ssh);
continue;
}
}
if (wolfSSH_stream_peek(threadCtx->ssh, tmp, 1) > 0) {

View File

@ -2654,7 +2654,8 @@ static int DoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
ret = SendKexInit(ssh);
}
if (ret == WS_SUCCESS)
/* account for possible want write case from SendKexInit */
if (ret == WS_SUCCESS || ret == WS_WANT_WRITE)
ret = wc_HashInit(&ssh->handshake->hash, enmhashId);
if (ret == WS_SUCCESS) {
@ -2720,6 +2721,10 @@ static int DoKexInit(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
ssh->clientState = CLIENT_KEXINIT_DONE;
else
ssh->serverState = SERVER_KEXINIT_DONE;
if (ssh->error != 0)
ret = ssh->error; /* propogate potential want write case from
SendKexInit*/
}
}
WLOG(WS_LOG_DEBUG, "Leaving DoKexInit(), ret = %d", ret);
@ -6334,7 +6339,7 @@ int DoReceive(WOLFSSH* ssh)
ret = DoPacket(ssh);
ssh->error = ret;
if (ret < 0 && !(ret == WS_CHAN_RXD || ret == WS_EXTDATA ||
ret == WS_CHANNEL_CLOSED)) {
ret == WS_CHANNEL_CLOSED || ret == WS_WANT_WRITE)) {
return WS_FATAL_ERROR;
}
WLOG(WS_LOG_DEBUG, "PR3: peerMacSz = %u", peerMacSz);

View File

@ -395,6 +395,15 @@ int wolfSSH_accept(WOLFSSH* ssh)
if (ssh == NULL)
return WS_BAD_ARGUMENT;
/* clear want read/writes for retry */
if (ssh->error == WS_WANT_READ || ssh->error == WS_WANT_WRITE)
ssh->error = 0;
if (ssh->error != 0) {
WLOG(WS_LOG_DEBUG, "Calling wolfSSH_accept in error state");
return WS_INVALID_STATE_E;
}
/* check if data pending to be sent */
if (ssh->outputBuffer.length > 0 &&
ssh->acceptState < ACCEPT_CLIENT_SESSION_ESTABLISHED) {

View File

@ -513,6 +513,13 @@ static int wolfSSH_SFTP_buffer_send(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer)
if (ret > 0) {
buffer->idx += ret;
}
if (ret == WS_WANT_WRITE) {
/* data was stored in out buffer of ssh struct but not sent
* still advance the SFTP buffer index */
buffer->idx += buffer->sz - buffer->idx;
}
} while (buffer->idx < buffer->sz && (ret > 0 || ret == WS_SUCCESS));
return ret;
@ -1203,7 +1210,7 @@ static int wolfSSH_SFTP_RecvRealPath(WOLFSSH* ssh, int reqId, byte* data,
* Lots of peers send a '.' wanting a return of the current absolute path
* not the absolute path + .
*/
if (r[rSz - 2] == WS_DELIM && r[rSz - 1] == '.') {
if (rSz > 2 && r[rSz - 2] == WS_DELIM && r[rSz - 1] == '.') {
r[rSz - 1] = '\0';
rSz -= 1;
}