@@ -1899,5 +1899,40 @@ int test_wolfSSL_BIO_get_init(void)
18991899 return EXPECT_RESULT ();
19001900}
19011901
1902+ int test_wolfSSL_BIO_get_new_index (void )
1903+ {
1904+ EXPECT_DECLS ;
1905+ #if defined(OPENSSL_EXTRA )
1906+ BIO_METHOD * method = NULL ;
1907+ BIO * bio = NULL ;
1908+ int idx = 0 ;
1909+ int prev ;
1910+
1911+ /* First call hands out BIO_TYPE_START + 1, later calls increment by
1912+ * one. The index counter is process-global, so this test drains it
1913+ * completely; it must stay the only consumer in the test suite. */
1914+ ExpectIntEQ (prev = BIO_get_new_index (), BIO_TYPE_START + 1 );
1915+
1916+ /* A returned index is usable as a custom method type. */
1917+ ExpectNotNull (method = BIO_meth_new (prev , "new_index_test" ));
1918+ ExpectNotNull (bio = BIO_new (method ));
1919+ ExpectIntEQ (BIO_method_type (bio ), prev );
1920+ BIO_free (bio );
1921+ BIO_meth_free (method );
1922+
1923+ /* Monotonic by one up to the last valid index 0xff, then
1924+ * WOLFSSL_FATAL_ERROR once exhausted. */
1925+ while (EXPECT_SUCCESS () && (idx = BIO_get_new_index ()) > 0 ) {
1926+ ExpectIntEQ (idx , prev + 1 );
1927+ prev = idx ;
1928+ }
1929+ ExpectIntEQ (prev , 0xff );
1930+ ExpectIntEQ (idx , WOLFSSL_FATAL_ERROR );
1931+ /* Exhaustion is sticky. */
1932+ ExpectIntEQ (BIO_get_new_index (), WOLFSSL_FATAL_ERROR );
1933+ #endif
1934+ return EXPECT_RESULT ();
1935+ }
1936+
19021937#endif /* !NO_BIO */
19031938
0 commit comments