@@ -390,6 +390,65 @@ static int test_provide_quic_data(void) {
390390 return EXPECT_RESULT ();
391391}
392392
393+ static int test_quic_record_cap (void ) {
394+ EXPECT_DECLS ;
395+ WOLFSSL_CTX * ctx = NULL ;
396+ WOLFSSL * ssl = NULL ;
397+ size_t over = (size_t )WOLFSSL_QUIC_MAX_RECORD_CAPACITY + 512U * 1024U ;
398+ uint8_t * buf = NULL ;
399+ uint8_t hdr [4 ];
400+ word32 rlen ;
401+
402+ ExpectNotNull (buf = (uint8_t * )XMALLOC (over , NULL , DYNAMIC_TYPE_TMP_BUFFER ));
403+ if (buf != NULL )
404+ XMEMSET (buf , 0 , over );
405+
406+ ExpectNotNull (ctx = wolfSSL_CTX_new (wolfTLSv1_3_client_method ()));
407+ ExpectTrue (wolfSSL_CTX_set_quic_method (ctx , & dummy_method ) == WOLFSSL_SUCCESS );
408+
409+ /* early_data with over-cap length must be rejected */
410+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
411+ ExpectTrue (provide_data (ssl , wolfssl_encryption_early_data , buf , over , 1 ));
412+ wolfSSL_free (ssl );
413+ ssl = NULL ;
414+
415+ /* early_data at exactly cap must succeed */
416+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
417+ ExpectTrue (provide_data (ssl , wolfssl_encryption_early_data , buf ,
418+ WOLFSSL_QUIC_MAX_RECORD_CAPACITY , 0 ));
419+ wolfSSL_free (ssl );
420+ ssl = NULL ;
421+
422+ /* early_data at cap+1 must be rejected */
423+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
424+ ExpectTrue (provide_data (ssl , wolfssl_encryption_early_data , buf ,
425+ (size_t )WOLFSSL_QUIC_MAX_RECORD_CAPACITY + 1U , 1 ));
426+ wolfSSL_free (ssl );
427+ ssl = NULL ;
428+
429+ /* early_data well within cap must succeed */
430+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
431+ ExpectTrue (provide_data (ssl , wolfssl_encryption_early_data , buf , 1024 , 0 ));
432+ wolfSSL_free (ssl );
433+ ssl = NULL ;
434+
435+ /* handshake with over-cap record header must also be rejected */
436+ rlen = (word32 )WOLFSSL_QUIC_MAX_RECORD_CAPACITY + 16U - 4U ;
437+ hdr [0 ] = 0x16 ;
438+ hdr [1 ] = (byte )(rlen >> 16 );
439+ hdr [2 ] = (byte )(rlen >> 8 );
440+ hdr [3 ] = (byte )rlen ;
441+ ExpectNotNull (ssl = wolfSSL_new (ctx ));
442+ ExpectTrue (provide_data (ssl , wolfssl_encryption_handshake , hdr , 4 , 1 ));
443+ wolfSSL_free (ssl );
444+
445+ wolfSSL_CTX_free (ctx );
446+ if (buf != NULL )
447+ XFREE (buf , NULL , DYNAMIC_TYPE_TMP_BUFFER );
448+
449+ printf (" test_quic_record_cap: %s\n" , (EXPECT_SUCCESS ()) ? pass : fail );
450+ return EXPECT_RESULT ();
451+ }
393452
394453static int test_quic_crypt (void ) {
395454 EXPECT_DECLS ;
@@ -1939,6 +1998,7 @@ int QuicTest(void)
19391998 if ((ret = test_set_quic_method ()) != TEST_SUCCESS ) goto leave ;
19401999#ifndef NO_WOLFSSL_CLIENT
19412000 if ((ret = test_provide_quic_data ()) != TEST_SUCCESS ) goto leave ;
2001+ if ((ret = test_quic_record_cap ()) != TEST_SUCCESS ) goto leave ;
19422002 if ((ret = test_quic_crypt ()) != TEST_SUCCESS ) goto leave ;
19432003 if ((ret = test_quic_client_hello (verbose )) != TEST_SUCCESS ) goto leave ;
19442004#endif
0 commit comments