@@ -391,8 +391,11 @@ static int wsHighwater(byte dir, void* ctx)
391391}
392392
393393
394- static INLINE void HighwaterCheck (WOLFSSH * ssh , byte side )
394+ /* returns WS_SUCCESS on success */
395+ static INLINE int HighwaterCheck (WOLFSSH * ssh , byte side )
395396{
397+ int ret = WS_SUCCESS ;
398+
396399 if (!ssh -> highwaterFlag && ssh -> highwaterMark &&
397400 (ssh -> txCount >= ssh -> highwaterMark ||
398401 ssh -> rxCount >= ssh -> highwaterMark )) {
@@ -403,8 +406,9 @@ static INLINE void HighwaterCheck(WOLFSSH* ssh, byte side)
403406 ssh -> highwaterFlag = 1 ;
404407
405408 if (ssh -> ctx -> highwaterCb )
406- ssh -> ctx -> highwaterCb (side , ssh -> highwaterCtx );
409+ ret = ssh -> ctx -> highwaterCb (side , ssh -> highwaterCtx );
407410 }
411+ return ret ;
408412}
409413
410414
@@ -1433,7 +1437,7 @@ int GrowBuffer(Buffer* buf, word32 sz, word32 usedSz)
14331437 }
14341438
14351439 /*WLOG(WS_LOG_DEBUG, "GB: resizing buffer");*/
1436- if (buf -> length > 0 )
1440+ if (buf -> length > 0 && usedSz > 0 )
14371441 WMEMCPY (newBuffer , buf -> buffer + buf -> idx , usedSz );
14381442
14391443 if (!buf -> dynamicFlag )
@@ -1576,6 +1580,7 @@ static int GetInputText(WOLFSSH* ssh, byte** pEol)
15761580}
15771581
15781582
1583+ /* returns WS_SUCCESS on success */
15791584int wolfSSH_SendPacket (WOLFSSH * ssh )
15801585{
15811586 WLOG (WS_LOG_DEBUG , "Entering wolfSSH_SendPacket()" );
@@ -1634,10 +1639,7 @@ int wolfSSH_SendPacket(WOLFSSH* ssh)
16341639
16351640 WLOG (WS_LOG_DEBUG , "SB: Shrinking output buffer" );
16361641 ShrinkBuffer (& ssh -> outputBuffer , 0 );
1637-
1638- HighwaterCheck (ssh , WOLFSSH_HWSIDE_TRANSMIT );
1639-
1640- return WS_SUCCESS ;
1642+ return HighwaterCheck (ssh , WOLFSSH_HWSIDE_TRANSMIT );
16411643}
16421644
16431645
@@ -5527,7 +5529,9 @@ static INLINE int Decrypt(WOLFSSH* ssh, byte* plain, const byte* input,
55275529 }
55285530
55295531 ssh -> rxCount += sz ;
5530- HighwaterCheck (ssh , WOLFSSH_HWSIDE_RECEIVE );
5532+
5533+ if (ret == WS_SUCCESS )
5534+ ret = HighwaterCheck (ssh , WOLFSSH_HWSIDE_RECEIVE );
55315535
55325536 return ret ;
55335537}
@@ -5752,7 +5756,9 @@ static INLINE int DecryptAead(WOLFSSH* ssh, byte* plain,
57525756
57535757 AeadIncrementExpIv (ssh -> peerKeys .iv );
57545758 ssh -> rxCount += sz ;
5755- HighwaterCheck (ssh , WOLFSSH_HWSIDE_RECEIVE );
5759+
5760+ if (ret == WS_SUCCESS )
5761+ ret = HighwaterCheck (ssh , WOLFSSH_HWSIDE_RECEIVE );
57565762
57575763 return ret ;
57585764}
@@ -6350,8 +6356,6 @@ int SendKexInit(WOLFSSH* ssh)
63506356 c32toa (0 , output + idx ); /* Reserved (0) */
63516357 idx += LENGTH_SZ ;
63526358
6353- ssh -> outputBuffer .length = idx ;
6354-
63556359 if (ssh -> handshake -> kexInit != NULL ) {
63566360 WFREE (ssh -> handshake -> kexInit , ssh -> ctx -> heap , DYNTYPE_STRING );
63576361 ssh -> handshake -> kexInit = NULL ;
@@ -6371,8 +6375,11 @@ int SendKexInit(WOLFSSH* ssh)
63716375 }
63726376 }
63736377
6374- if (ret == WS_SUCCESS )
6378+ if (ret == WS_SUCCESS ) {
6379+ /* increase amount to be sent only if BundlePacket will be called */
6380+ ssh -> outputBuffer .length = idx ;
63756381 ret = BundlePacket (ssh );
6382+ }
63766383
63776384 if (ret == WS_SUCCESS )
63786385 ret = wolfSSH_SendPacket (ssh );
0 commit comments