From 84785ffe39463bfa982c901a718d3514fd214a33 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Tue, 11 Feb 2020 14:41:14 -0700 Subject: [PATCH 1/3] exit channel in echoserver before sending disconnect --- examples/echoserver/echoserver.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index e7ed95a..abcabd9 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -442,9 +442,13 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) if (error != WS_SOCKET_ERROR_E && error != WS_FATAL_ERROR) { + if (wolfSSH_stream_exit(threadCtx->ssh, 0) != WS_SUCCESS) { + fprintf(stderr, "Error with SSH stream exit.\n"); + } if (wolfSSH_shutdown(threadCtx->ssh) != WS_SUCCESS) { fprintf(stderr, "Error with SSH shutdown.\n"); } + } WCLOSESOCKET(threadCtx->fd); From 9b7700cd6bb92b48d537f099451455a9c942c3ae Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 14 Feb 2020 17:52:25 -0700 Subject: [PATCH 2/3] adjust stream exit in scp case --- examples/echoserver/echoserver.c | 20 ++++++++++++++------ src/ssh.c | 5 +++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index abcabd9..3c9fe0f 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -401,8 +401,20 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) switch (ret) { case WS_SCP_COMPLETE: - printf("scp file transfer completed\n"); - ret = 0; + { + byte buf[1]; + printf("scp file transfer completed\n"); + if (wolfSSH_stream_exit(threadCtx->ssh, 0) != WS_SUCCESS) { + fprintf(stderr, "Error with SSH stream exit.\n"); + } + /* Peer MUST send back a SSH_MSG_CHANNEL_CLOSE unless already + * sent*/ + ret = wolfSSH_stream_read(threadCtx->ssh, buf, 1); + if (ret != WS_EOF) { + fprintf(stderr, "Was expecting EOF\n"); + } + ret = 0; + } break; case WS_SFTP_COMPLETE: @@ -442,13 +454,9 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) if (error != WS_SOCKET_ERROR_E && error != WS_FATAL_ERROR) { - if (wolfSSH_stream_exit(threadCtx->ssh, 0) != WS_SUCCESS) { - fprintf(stderr, "Error with SSH stream exit.\n"); - } if (wolfSSH_shutdown(threadCtx->ssh) != WS_SUCCESS) { fprintf(stderr, "Error with SSH shutdown.\n"); } - } WCLOSESOCKET(threadCtx->fd); diff --git a/src/ssh.c b/src/ssh.c index b5d52db..a476a3b 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -878,6 +878,11 @@ int wolfSSH_shutdown(WOLFSSH* ssh) if (ret == WS_SUCCESS) ret = SendDisconnect(ssh, WOLFSSH_DISCONNECT_BY_APPLICATION); + if (ssh->channelList == NULL) { + WLOG(WS_LOG_DEBUG, "channel list was already removed"); + ret = WS_SUCCESS; + } + WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_shutdown(), ret = %d", ret); return ret; } From aa3fcc71a44e3f9c76543f4fe572d9b645b4abe8 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Wed, 19 Feb 2020 10:17:12 -0700 Subject: [PATCH 3/3] fix for scan-build warning --- src/ssh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ssh.c b/src/ssh.c index a476a3b..d290641 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -878,7 +878,7 @@ int wolfSSH_shutdown(WOLFSSH* ssh) if (ret == WS_SUCCESS) ret = SendDisconnect(ssh, WOLFSSH_DISCONNECT_BY_APPLICATION); - if (ssh->channelList == NULL) { + if (ssh != NULL && ssh->channelList == NULL) { WLOG(WS_LOG_DEBUG, "channel list was already removed"); ret = WS_SUCCESS; }