Skip to content

Commit 524b5c6

Browse files
authored
Merge pull request #702 from JacobBarthelmeh/scp_example
adjust scp error return checking for closed channels
2 parents 3024d28 + c3aaa6e commit 524b5c6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

examples/scpclient/scpclient.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
325325
WCLOSESOCKET(sockFd);
326326
wolfSSH_free(ssh);
327327
wolfSSH_CTX_free(ctx);
328-
if (ret != WS_SUCCESS && ret != WS_SOCKET_ERROR_E)
328+
if (ret != WS_SUCCESS && ret != WS_SOCKET_ERROR_E &&
329+
ret != WS_CHANNEL_CLOSED) {
329330
err_sys("Closing scp stream failed. Connection could have been closed by peer");
331+
}
330332

331333
ClientFreeBuffers(pubKeyName, privKeyName, NULL);
332334
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)

src/wolfscp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,11 @@ int DoScpRequest(WOLFSSH* ssh)
730730
/* Peer MUST send back a SSH_MSG_CHANNEL_CLOSE unless already
731731
sent*/
732732
ret = wolfSSH_stream_read(ssh, buf, 1);
733-
if (ret != WS_EOF) {
733+
if (ret == WS_SOCKET_ERROR_E || ret == WS_CHANNEL_CLOSED) {
734+
WLOG(WS_LOG_DEBUG, scpState, "Peer hung up, but SCP is done");
735+
ret = WS_SUCCESS;
736+
}
737+
else if (ret != WS_EOF) {
734738
WLOG(WS_LOG_DEBUG, scpState, "Did not receive EOF packet");
735739
}
736740
else {

0 commit comments

Comments
 (0)