Skip to content

Commit

Permalink
Merge pull request #702 from JacobBarthelmeh/scp_example
Browse files Browse the repository at this point in the history
adjust scp error return checking for closed channels
  • Loading branch information
ejohnstown authored Jun 5, 2024
2 parents 3024d28 + c3aaa6e commit 524b5c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion examples/scpclient/scpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
WCLOSESOCKET(sockFd);
wolfSSH_free(ssh);
wolfSSH_CTX_free(ctx);
if (ret != WS_SUCCESS && ret != WS_SOCKET_ERROR_E)
if (ret != WS_SUCCESS && ret != WS_SOCKET_ERROR_E &&
ret != WS_CHANNEL_CLOSED) {
err_sys("Closing scp stream failed. Connection could have been closed by peer");
}

ClientFreeBuffers(pubKeyName, privKeyName, NULL);
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
Expand Down
6 changes: 5 additions & 1 deletion src/wolfscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,11 @@ int DoScpRequest(WOLFSSH* ssh)
/* Peer MUST send back a SSH_MSG_CHANNEL_CLOSE unless already
sent*/
ret = wolfSSH_stream_read(ssh, buf, 1);
if (ret != WS_EOF) {
if (ret == WS_SOCKET_ERROR_E || ret == WS_CHANNEL_CLOSED) {
WLOG(WS_LOG_DEBUG, scpState, "Peer hung up, but SCP is done");
ret = WS_SUCCESS;
}
else if (ret != WS_EOF) {
WLOG(WS_LOG_DEBUG, scpState, "Did not receive EOF packet");
}
else {
Expand Down

0 comments on commit 524b5c6

Please sign in to comment.