From f59ea6f1acad1591f69e471d204fa4b0c1fa8821 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 11 Sep 2019 10:54:26 -0700 Subject: [PATCH 1/6] Maintenance Fix a typo in a string. --- examples/echoserver/echoserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index 6ffd3ce..379ff66 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -1013,7 +1013,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) WMEMCPY(ipaddr, &sock.ip_num, MAX_ADDRESS_SIZE); NU_Inet_NTOP(NU_FAMILY_IP, &ipaddr[0], buf, 16); - fprintf(stdout, "Listing on %s:%d\r\n", buf, port); + fprintf(stdout, "Listening on %s:%d\r\n", buf, port); } #endif From acd80a1976c3fc1b7fd612b612ac499753b2d347 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 11 Sep 2019 10:54:59 -0700 Subject: [PATCH 2/6] Maintenance When DoReceive starts, it saves a copy of the current peerMacSz. After the call to DoPacket, it adds the peerMacSz size to the input buffer index, then calls ShrinkBuffer(). Because it was adding the session stored peerMacSz, and not the local copy, the input buffer was appearing to be overrun in one packet case, NEW_KEYS. This message updates the session's peerMacSz, but it's mac size is still the old size. --- src/internal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 7108c6c..0e82bfa 100644 --- a/src/internal.c +++ b/src/internal.c @@ -5124,8 +5124,8 @@ int DoReceive(WOLFSSH* ssh) ssh->error = ret; return WS_FATAL_ERROR; } - WLOG(WS_LOG_DEBUG, "PR3: peerMacSz = %u", ssh->peerMacSz); - ssh->inputBuffer.idx += ssh->peerMacSz; + WLOG(WS_LOG_DEBUG, "PR3: peerMacSz = %u", peerMacSz); + ssh->inputBuffer.idx += peerMacSz; break; default: From 365be7d63cf4be004974bc4502c49d1e242f8934 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 11 Sep 2019 14:10:16 -0700 Subject: [PATCH 3/6] Maintenance 1. Clean up a few compiler warnings. 2. Between Windows, MacOS, and Linux, the %llu printf tag varies slightly, add a typecast of the word64 to unsigned long long to hush the compiler warning. --- examples/sftpclient/sftpclient.c | 7 ++++--- src/wolfsftp.c | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index 97db63f..297014e 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -53,7 +53,8 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) { char buf[80]; word64 longBytes = ((word64)bytes[1] << 32) | bytes[0]; - WSNPRINTF(buf, sizeof(buf), "Processed %8ld\t bytes \r", longBytes); + WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes \r", + (unsigned long long)longBytes); WFPUTS(buf, fout); (void)name; (void)sshIn; @@ -1229,7 +1230,7 @@ THREAD_RETURN WOLFSSH_THREAD sftpclient_test(void* args) (word32)WSTRLEN(hanselPublicEcc), (byte*)userPublicKey, &userPublicKeySz); - strncpy((char*)userPublicKeyType, "ecdsa-sha2-nistp256", + WSTRNCPY((char*)userPublicKeyType, "ecdsa-sha2-nistp256", sizeof(userPublicKeyType)); userPrivateKey = hanselPrivateEcc; userPrivateKeySz = hanselPrivateEccSz; @@ -1240,7 +1241,7 @@ THREAD_RETURN WOLFSSH_THREAD sftpclient_test(void* args) (word32)WSTRLEN(hanselPublicRsa), (byte*)userPublicKey, &userPublicKeySz); - strncpy((char*)userPublicKeyType, "ssh-rsa", + WSTRNCPY((char*)userPublicKeyType, "ssh-rsa", sizeof(userPublicKeyType)); userPrivateKey = hanselPrivateRsa; userPrivateKeySz = hanselPrivateRsaSz; diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 48ab7f4..19c0166 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -7287,7 +7287,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, if (resume) { WMEMSET(&state->offset, 0, sizeof(OVERLAPPED)); state->offset.OffsetHigh = 0; - state->offset.Offset = (DWORD)state->pOfst; + state->offset.Offset = state->pOfst[0]; } #endif /* USE_WINDOWS_API */ state->rSz = 0; @@ -7342,7 +7342,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume, AddAssign64(state->pOfst, sz); #ifdef USE_WINDOWS_API state->offset.OffsetHigh = 0; - state->offset.Offset = (DWORD)state->pOfst; + state->offset.Offset = state->pOfst[0]; #endif /* USE_WINDOWS_API */ state->rSz -= sz; if (statusCb != NULL) { From 66ff87c0a8701d4ce3a085ee02b0e28b8c23879b Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 12 Sep 2019 14:04:10 -0700 Subject: [PATCH 4/6] Remove a confusing log entry with a comment. --- src/internal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 0e82bfa..5b5df5a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -5066,8 +5066,8 @@ int DoReceive(WOLFSSH* ssh) ssh->curSz + LENGTH_SZ - peerBlockSz); } else { - WLOG(WS_LOG_INFO, - "Not trying to decrypt short message."); + /* Entire packet fit in one block, don't need + * to decrypt any more data this packet. */ } /* Verify the buffer is big enough for the data and mac. From 915c1bced97aa1aa03ffead00ff102f695e9ee55 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 12 Sep 2019 16:13:47 -0700 Subject: [PATCH 5/6] Add a public API for the SendDisconnect() function. --- src/ssh.c | 6 ++++++ wolfssh/ssh.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/ssh.c b/src/ssh.c index d08aae9..4741a60 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -1022,6 +1022,12 @@ int wolfSSH_SendIgnore(WOLFSSH* ssh, const byte* buf, word32 bufSz) } +int wolfSSH_SendDisconnect(WOLFSSH* ssh, word32 reason) +{ + return SendDisconnect(ssh, reason); +} + + void wolfSSH_SetUserAuth(WOLFSSH_CTX* ctx, WS_CallbackUserAuth cb) { if (ctx != NULL) { diff --git a/wolfssh/ssh.h b/wolfssh/ssh.h index df49c63..f2657ab 100644 --- a/wolfssh/ssh.h +++ b/wolfssh/ssh.h @@ -184,6 +184,7 @@ WOLFSSH_API int wolfSSH_stream_exit(WOLFSSH*, int); WOLFSSH_API int wolfSSH_extended_data_read(WOLFSSH*, byte*, word32); WOLFSSH_API int wolfSSH_TriggerKeyExchange(WOLFSSH*); WOLFSSH_API int wolfSSH_SendIgnore(WOLFSSH*, const byte*, word32); +WOLFSSH_API int wolfSSH_SendDisconnect(WOLFSSH*, word32); WOLFSSH_API int wolfSSH_global_request(WOLFSSH*, const unsigned char*, word32, int); WOLFSSH_API void wolfSSH_GetStats(WOLFSSH*, From 1ad4ea3232daf8fa2c762b75b08b9e9ae330e156 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 13 Sep 2019 09:52:05 -0700 Subject: [PATCH 6/6] Fix off by one error in SCP command processing. --- src/wolfscp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wolfscp.c b/src/wolfscp.c index 3b8ccd0..4ea2d4c 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -1259,7 +1259,7 @@ int ReceiveScpMessage(WOLFSSH* ssh) return sz; /* null-terminate request, replace newline */ - buf[sz-1] = '\0'; + buf[sz] = '\0'; switch (buf[0]) { case 'C':