Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,19 @@ static THREAD_RET readPeer(void* in)
}
#endif /* WOLFSSH_AGENT */
else if (ret == WS_REKEYING) {
wolfSSH_worker(args->ssh, NULL);
ret = 0;
/* Drive the key exchange. A read keeps answering
* WS_REKEYING while it runs, so a transport failure
* shows up only here; end the session on it. */
ret = wolfSSH_worker(args->ssh, NULL);
if (ret == WS_FATAL_ERROR) {
ret = wolfSSH_get_error(args->ssh);
}
if (ret == WS_SUCCESS || ret == WS_WANT_READ
|| ret == WS_WANT_WRITE || ret == WS_REKEYING
|| ret == WS_CHAN_RXD || ret == WS_EXTDATA
|| ret == WS_EOF || ret == WS_CHANNEL_CLOSED) {
ret = 0;
}
}
}
else if (ret != WS_EOF) {
Expand Down
5 changes: 5 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ static INLINE int HighwaterCheck(WOLFSSH* ssh, byte side)
if (fire && ssh->ctx->highwaterCb)
ret = ssh->ctx->highwaterCb(side, ssh->highwaterCtx);

/* The result travels back through calls that return byte counts, such
* as wolfSSH_stream_read(), so a positive one would read as data. */
if (ret > 0)
ret = WS_SUCCESS;

return ret;
}

Expand Down
2 changes: 0 additions & 2 deletions src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,6 @@ int ReceiveScpMessage(WOLFSSH* ssh)
if (sz <= 0)
return sz;
ssh->scpRecvMsgSz += sz;
sz = ssh->scpRecvMsgSz;
continue;
}

Expand All @@ -2004,7 +2003,6 @@ int ReceiveScpMessage(WOLFSSH* ssh)
return sz;
}
ssh->scpRecvMsgSz += sz;
sz = ssh->scpRecvMsgSz;
break;

case WS_EXTDATA:
Expand Down
13 changes: 11 additions & 2 deletions src/wolfsftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -9066,9 +9066,18 @@ int wolfSSH_SFTP_SendReadPacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
break;
}

/* A count over the request wraps to a growth, which
* set_size refuses. */
if (wolfSSH_SFTP_buffer_set_size(&state->buffer,
wolfSSH_SFTP_buffer_size(&state->buffer)
- (word32)ret) != WS_SUCCESS) {
WLOG(WS_LOG_SFTP, "Read more data than requested");
ssh->error = WS_BUFFER_E;
ret = WS_FATAL_ERROR;
state->state = STATE_SEND_READ_CLEANUP;
break;
}
state->recvSz += ret;
wolfSSH_SFTP_buffer_set_size(&state->buffer,
wolfSSH_SFTP_buffer_size(&state->buffer) - ret);
} while (wolfSSH_SFTP_buffer_size(&state->buffer) != 0);

if (ret < 0) {
Expand Down
29 changes: 28 additions & 1 deletion tests/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5316,18 +5316,22 @@ typedef struct HwTestCtx {
WOLFSSH* ssh;
int count;
int keying;
int ret;
byte lastSide;
} HwTestCtx;

static int HwTestCb(byte side, void* ctx)
{
HwTestCtx* hc = (HwTestCtx*)ctx;
int ret = WS_SUCCESS;

if (hc != NULL) {
hc->count++;
hc->lastSide = side;
hc->keying = wolfSSH_RekeyPending(hc->ssh);
ret = hc->ret;
}
return WS_SUCCESS;
return ret;
}

/* Exercise the wolfSSH_*MsgHighwater APIs and the per-key packet-count
Expand Down Expand Up @@ -5533,6 +5537,29 @@ static int test_ByteHighwater(void)
goto done;
}

/* A positive callback result is not a status: it would reach callers
* that return byte counts, so it comes back as WS_SUCCESS. A negative
* one passes through. */
if (wolfSSH_SetHighwater(ssh, 1024) != WS_SUCCESS) {
result = -829;
goto done;
}
hc.ret = 4096;
ssh->highwaterFlag = 0;
ssh->txCount = 1024;
if (wolfSSH_TestHighwaterCheck(ssh, WOLFSSH_HWSIDE_TRANSMIT) != WS_SUCCESS
|| hc.count != 3) {
result = -830;
goto done;
}
hc.ret = WS_WANT_WRITE;
ssh->highwaterFlag = 0;
if (wolfSSH_TestHighwaterCheck(ssh, WOLFSSH_HWSIDE_TRANSMIT)
!= WS_WANT_WRITE || hc.count != 4) {
result = -831;
goto done;
}

done:
wolfSSH_free(ssh);
wolfSSH_CTX_free(ctx);
Expand Down
Loading