@@ -978,7 +978,8 @@ static int Dtls13SendOneFragmentRtx(WOLFSSL* ssl,
978978static int Dtls13SendFragmentedInternal (WOLFSSL * ssl )
979979{
980980 int fragLength , rlHeaderLength ;
981- int remainingSize , maxFragment ;
981+ word32 remainingSize ;
982+ int maxFragment ;
982983 int recordLength , outputSz ;
983984 byte isEncrypted ;
984985 byte * output ;
@@ -988,16 +989,19 @@ static int Dtls13SendFragmentedInternal(WOLFSSL* ssl)
988989 (enum HandShakeType )ssl -> dtls13FragHandshakeType );
989990 rlHeaderLength = Dtls13GetRlHeaderLength (ssl , isEncrypted );
990991 maxFragment = wolfssl_local_GetMaxPlaintextSize (ssl );
991-
992+ if (maxFragment <= DTLS_HANDSHAKE_HEADER_SZ ||
993+ maxFragment > MAX_RECORD_SIZE ||
994+ ssl -> dtls13FragOffset > ssl -> dtls13MessageLength ) {
995+ Dtls13FreeFragmentsBuffer (ssl );
996+ return BUFFER_E ;
997+ }
992998 remainingSize = ssl -> dtls13MessageLength - ssl -> dtls13FragOffset ;
993999
9941000 while (remainingSize > 0 ) {
9951001
9961002 fragLength = maxFragment - DTLS_HANDSHAKE_HEADER_SZ ;
997-
998- if (fragLength > remainingSize ) {
999- fragLength = remainingSize ;
1000- }
1003+ if (fragLength > (int )remainingSize )
1004+ fragLength = (int )remainingSize ;
10011005
10021006 recordLength = fragLength + rlHeaderLength + DTLS_HANDSHAKE_HEADER_SZ ;
10031007 outputSz = wolfssl_local_GetRecordSize (ssl ,
@@ -1041,7 +1045,7 @@ static int Dtls13SendFragmentedInternal(WOLFSSL* ssl)
10411045 }
10421046
10431047 ssl -> dtls13FragOffset += fragLength ;
1044- remainingSize -= fragLength ;
1048+ remainingSize -= ( word32 ) fragLength ;
10451049 }
10461050
10471051 /* we sent all fragments */
0 commit comments