@@ -546,66 +546,8 @@ int test_certificate_authorities_client_hello(void) {
546546 return EXPECT_RESULT ();
547547}
548548
549- #if defined(HAVE_SNI ) && !defined(NO_WOLFSSL_CLIENT ) && !defined(NO_TLS )
550- /* Walk the TLSX list to find an extension by type. */
551- static TLSX * test_TLSX_find_ext_sni (TLSX * list , TLSX_Type type )
552- {
553- while (list ) {
554- if (list -> type == type )
555- return list ;
556- list = list -> next ;
557- }
558- return NULL ;
559- }
560-
561- /* Replicate the SNI size calculation to test overflow protection.
562- * The fixed TLSX_SNI_GetSize uses word32 internally and returns 0 on
563- * overflow. This helper mirrors that logic so we can verify the behavior. */
564- static word16 test_SNI_GetSize (SNI * list )
565- {
566- SNI * sni ;
567- word32 length = OPAQUE16_LEN ;
568-
569- while ((sni = list )) {
570- list = sni -> next ;
571- length += ENUM_LEN + OPAQUE16_LEN ;
572- switch (sni -> type ) {
573- case WOLFSSL_SNI_HOST_NAME :
574- length += (word16 )XSTRLEN ((char * )sni -> data .host_name );
575- break ;
576- }
577- if (length > WOLFSSL_MAX_16BIT )
578- return 0 ;
579- }
580- return (word16 )length ;
581- }
582-
583- /* Replicate the old (vulnerable) SNI size calculation using word16 to
584- * demonstrate the overflow that the fix prevents. */
585- static word16 test_SNI_GetSize_old (SNI * list )
586- {
587- SNI * sni ;
588- word16 length = OPAQUE16_LEN ;
589-
590- while ((sni = list )) {
591- list = sni -> next ;
592- length += ENUM_LEN + OPAQUE16_LEN ;
593- switch (sni -> type ) {
594- case WOLFSSL_SNI_HOST_NAME :
595- /* Intentional truncation to word16 to mirror the original
596- * vulnerable implementation for testing overflow behavior. */
597- length += (word16 )XSTRLEN ((char * )sni -> data .host_name );
598- break ;
599- }
600- }
601- return length ;
602- }
603-
604549/* Test that the SNI size calculation returns 0 on overflow instead of
605550 * wrapping around to a small value (integer overflow vulnerability). */
606- /* closing #if for helper functions */
607- #endif /* HAVE_SNI && !NO_WOLFSSL_CLIENT && !NO_TLS */
608-
609551int test_TLSX_SNI_GetSize_overflow (void )
610552{
611553 EXPECT_DECLS ;
@@ -616,8 +558,6 @@ int test_TLSX_SNI_GetSize_overflow(void)
616558 SNI * head = NULL ;
617559 SNI * sni = NULL ;
618560 int i ;
619- word16 fixed_size ;
620- word16 old_size ;
621561 /* Each SNI adds ENUM_LEN(1) + OPAQUE16_LEN(2) + hostname_len to the size.
622562 * With a 1-byte hostname, each entry adds 4 bytes. Starting from
623563 * OPAQUE16_LEN(2) base, we need enough entries to exceed UINT16_MAX. */
@@ -632,7 +572,7 @@ int test_TLSX_SNI_GetSize_overflow(void)
632572
633573 /* Find the SNI extension and manually build a long chain */
634574 if (EXPECT_SUCCESS ()) {
635- sni_ext = test_TLSX_find_ext_sni (ssl -> extensions , TLSX_SERVER_NAME );
575+ sni_ext = TLSX_Find (ssl -> extensions , TLSX_SERVER_NAME );
636576 ExpectNotNull (sni_ext );
637577 }
638578
@@ -661,17 +601,7 @@ int test_TLSX_SNI_GetSize_overflow(void)
661601
662602 if (EXPECT_SUCCESS ()) {
663603 /* The fixed calculation should return 0 (overflow detected) */
664- fixed_size = test_SNI_GetSize ((SNI * )sni_ext -> data );
665- ExpectIntEQ (fixed_size , 0 );
666-
667- /* The old (vulnerable) calculation would wrap around to a small value.
668- * The unwrapped total is approximately OPAQUE16_LEN + num_sni * 4,
669- * which is ~65,542. After wrapping past UINT16_MAX the result should
670- * be drastically smaller than that expected total. */
671- old_size = test_SNI_GetSize_old ((SNI * )sni_ext -> data );
672- ExpectIntNE (old_size , 0 );
673- ExpectIntLT (old_size ,
674- OPAQUE16_LEN + num_sni * (ENUM_LEN + OPAQUE16_LEN + 1 ));
604+ ExpectIntEQ (TLSX_SNI_GetSize ((SNI * )sni_ext -> data ), 0 );
675605 }
676606
677607 wolfSSL_free (ssl );
0 commit comments