@@ -918,7 +918,7 @@ int test_dtls13_ack_order(void)
918918 ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 2 ), w64From32 (0 , 2 )), 0 );
919919 ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 2 ), w64From32 (0 , 2 )), 0 );
920920 ExpectIntEQ (Dtls13WriteAckMessage (ssl_c , ssl_c -> dtls13Rtx .seenRecords ,
921- & length ), 0 );
921+ ssl_c -> dtls13Rtx . seenRecordsCount , & length ), 0 );
922922
923923 /* must zero the span reserved for the header to avoid read of uninited
924924 * data.
@@ -939,6 +939,124 @@ int test_dtls13_ack_order(void)
939939 return EXPECT_RESULT ();
940940}
941941
942+ int test_dtls13_ack_overflow (void )
943+ {
944+ EXPECT_DECLS ;
945+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && defined(WOLFSSL_DTLS13 )
946+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
947+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
948+ struct test_memio_ctx test_ctx ;
949+ unsigned char readBuf [50 ];
950+ word32 length = 0 ;
951+ int i ;
952+
953+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
954+
955+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
956+ wolfDTLSv1_3_client_method , wolfDTLSv1_3_server_method ), 0 );
957+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
958+ ExpectIntEQ (wolfSSL_read (ssl_c , readBuf , sizeof (readBuf )), -1 );
959+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WOLFSSL_ERROR_WANT_READ );
960+ ExpectIntEQ (wolfSSL_read (ssl_s , readBuf , sizeof (readBuf )), -1 );
961+ ExpectIntEQ (wolfSSL_get_error (ssl_s , -1 ), WOLFSSL_ERROR_WANT_READ );
962+
963+ /* Edge case 1: one below limit - all inserts must succeed */
964+ for (i = 0 ; i < DTLS13_ACK_MAX_RECORDS - 1 ; i ++ ) {
965+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 0 ),
966+ w64From32 (0 , (word32 )i )), 0 );
967+ }
968+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , DTLS13_ACK_MAX_RECORDS - 1 );
969+
970+ /* Edge case 2: insert the last allowed record - must succeed */
971+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 0 ),
972+ w64From32 (0 , (word32 )(DTLS13_ACK_MAX_RECORDS - 1 ))), 0 );
973+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , DTLS13_ACK_MAX_RECORDS );
974+
975+ /* Writing a full-but-valid list must succeed */
976+ ExpectIntEQ (Dtls13WriteAckMessage (ssl_c , ssl_c -> dtls13Rtx .seenRecords ,
977+ ssl_c -> dtls13Rtx .seenRecordsCount , & length ), 0 );
978+
979+ /* Edge case 3: one over limit - must be silently dropped */
980+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 0 ),
981+ w64From32 (0 , (word32 )DTLS13_ACK_MAX_RECORDS )), 0 );
982+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , DTLS13_ACK_MAX_RECORDS );
983+
984+ /* Bypass the insert guard to force the list one element over the limit,
985+ * then verify Dtls13WriteAckMessage errors out instead of overflowing */
986+ ssl_c -> dtls13Rtx .seenRecordsCount = 0 ;
987+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 1 ),
988+ w64From32 (0 , (word32 )DTLS13_ACK_MAX_RECORDS )), 0 );
989+ ssl_c -> dtls13Rtx .seenRecordsCount = (word16 )(DTLS13_ACK_MAX_RECORDS + 1 );
990+ ExpectIntEQ (Dtls13WriteAckMessage (ssl_c , ssl_c -> dtls13Rtx .seenRecords ,
991+ ssl_c -> dtls13Rtx .seenRecordsCount , & length ), BUFFER_E );
992+
993+ wolfSSL_free (ssl_c );
994+ wolfSSL_CTX_free (ctx_c );
995+ wolfSSL_free (ssl_s );
996+ wolfSSL_CTX_free (ctx_s );
997+ #endif
998+ return EXPECT_RESULT ();
999+ }
1000+
1001+ int test_dtls13_ack_dup_write_counter (void )
1002+ {
1003+ EXPECT_DECLS ;
1004+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && defined(WOLFSSL_DTLS13 ) \
1005+ && defined(HAVE_WRITE_DUP )
1006+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
1007+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
1008+ WOLFSSL * ssl_c2 = NULL ;
1009+ struct test_memio_ctx test_ctx ;
1010+ unsigned char readBuf [50 ];
1011+ int i ;
1012+
1013+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
1014+
1015+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
1016+ wolfDTLSv1_3_client_method , wolfDTLSv1_3_server_method ), 0 );
1017+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
1018+ /* Drain any post-handshake messages */
1019+ ExpectIntEQ (wolfSSL_read (ssl_c , readBuf , sizeof (readBuf )), -1 );
1020+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WOLFSSL_ERROR_WANT_READ );
1021+ ExpectIntEQ (wolfSSL_read (ssl_s , readBuf , sizeof (readBuf )), -1 );
1022+ ExpectIntEQ (wolfSSL_get_error (ssl_s , -1 ), WOLFSSL_ERROR_WANT_READ );
1023+
1024+ /* Split ssl_c: ssl_c becomes READ_DUP_SIDE, ssl_c2 becomes WRITE_DUP_SIDE */
1025+ ExpectNotNull (ssl_c2 = wolfSSL_write_dup (ssl_c ));
1026+
1027+ /* Cycle 1: add records, trigger handoff, verify counter is reset to 0 */
1028+ for (i = 0 ; i < 5 ; i ++ )
1029+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ),
1030+ w64From32 (0 , (word32 )i )), 0 );
1031+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , 5 );
1032+ ssl_c -> dtls13Rtx .sendAcks = 1 ;
1033+ ExpectIntEQ (Dtls13DoScheduledWork (ssl_c ), 0 );
1034+ /* seenRecords ownership was transferred to dupWrite->sendAckList;
1035+ * seenRecordsCount must be reset to 0, not left at 5. */
1036+ ExpectNull (ssl_c -> dtls13Rtx .seenRecords );
1037+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , 0 );
1038+
1039+ /* Cycle 2 (different epoch to avoid the dup-filter): verify the counter
1040+ * did not accumulate across the previous transfer. Without the fix,
1041+ * seenRecordsCount would now be 10 after this second batch. */
1042+ for (i = 0 ; i < 5 ; i ++ )
1043+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 4 ),
1044+ w64From32 (0 , (word32 )i )), 0 );
1045+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , 5 );
1046+ ssl_c -> dtls13Rtx .sendAcks = 1 ;
1047+ ExpectIntEQ (Dtls13DoScheduledWork (ssl_c ), 0 );
1048+ ExpectNull (ssl_c -> dtls13Rtx .seenRecords );
1049+ ExpectIntEQ (ssl_c -> dtls13Rtx .seenRecordsCount , 0 );
1050+
1051+ wolfSSL_free (ssl_c );
1052+ wolfSSL_free (ssl_c2 );
1053+ wolfSSL_CTX_free (ctx_c );
1054+ wolfSSL_free (ssl_s );
1055+ wolfSSL_CTX_free (ctx_s );
1056+ #endif
1057+ return EXPECT_RESULT ();
1058+ }
1059+
9421060int test_dtls_version_checking (void )
9431061{
9441062 EXPECT_DECLS ;
0 commit comments