diff --git a/src/internal.c b/src/internal.c index a3358188..37f3adec 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6267,6 +6267,15 @@ static int BundlePacket(WOLFSSH* ssh) } +static void PurgePacket(WOLFSSH* ssh) +{ + ssh->packetStartIdx = 0; + ssh->outputBuffer.idx = 0; + ssh->outputBuffer.plainSz = 0; + ShrinkBuffer(&ssh->outputBuffer, 1); +} + + static INLINE void CopyNameList(byte* buf, word32* idx, const char* src, word32 srcSz) { @@ -6505,6 +6514,9 @@ int SendKexInit(WOLFSSH* ssh) if (ret == WS_SUCCESS) ret = wolfSSH_SendPacket(ssh); + if (ret != WS_WANT_WRITE && ret != WS_SUCCESS) + PurgePacket(ssh); + WLOG(WS_LOG_DEBUG, "Leaving SendKexInit(), ret = %d", ret); return ret; } @@ -7238,6 +7250,9 @@ int SendKexDhReply(WOLFSSH* ssh) if (ret == WS_SUCCESS) ret = SendNewKeys(ssh); + if (ret != WS_WANT_WRITE && ret != WS_SUCCESS) + PurgePacket(ssh); + WLOG(WS_LOG_DEBUG, "Leaving SendKexDhReply(), ret = %d", ret); #ifdef WOLFSSH_SMALL_STACK if (sigKeyBlock_ptr) @@ -8600,6 +8615,9 @@ int SendUserAuthRequest(WOLFSSH* ssh, byte authId, int addSig) if (ret == WS_SUCCESS) ret = wolfSSH_SendPacket(ssh); + if (ret != WS_WANT_WRITE && ret != WS_SUCCESS) + PurgePacket(ssh); + ForceZero(&authData, sizeof(WS_UserAuthData)); WLOG(WS_LOG_DEBUG, "Leaving SendUserAuthRequest(), ret = %d", ret); #ifdef WOLFSSH_SMALL_STACK