From c3aaa6e57094cb5480456cf33cbe66cb8e03f364 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Wed, 29 May 2024 13:44:58 -0600 Subject: [PATCH] adjust scp error return checking for closed channels --- examples/scpclient/scpclient.c | 4 +++- src/wolfscp.c | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/scpclient/scpclient.c b/examples/scpclient/scpclient.c index c0cc7602b..ddbc1992d 100644 --- a/examples/scpclient/scpclient.c +++ b/examples/scpclient/scpclient.c @@ -324,8 +324,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) diff --git a/src/wolfscp.c b/src/wolfscp.c index 33a55580a..57af018a4 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -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 {