Add test for session_save() on small buffers

This commit is contained in:
Manuel Pégourié-Gonnard 2019-05-23 10:38:11 +02:00 committed by Jarno Lamsa
parent 5b1674e0ba
commit f5fa0aa664
2 changed files with 59 additions and 0 deletions

View file

@ -8775,3 +8775,26 @@ ssl_serialise_session_load_save:42:"data_files/server5.crt"
Session serialisation, load-save: large ticket, cert Session serialisation, load-save: large ticket, cert
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
ssl_serialise_session_load_save:1023:"data_files/server5.crt" ssl_serialise_session_load_save:1023:"data_files/server5.crt"
Session serialisation, save buffer size: no ticket, no cert
ssl_serialise_session_save_buf_size:0:""
Session serialisation, save buffer size: small ticket, no cert
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C
ssl_serialise_session_save_buf_size:42:""
Session serialisation, save buffer size: large ticket, no cert
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C
ssl_serialise_session_save_buf_size:1023:""
Session serialisation, save buffer size: no ticket, cert
depends_on:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
ssl_serialise_session_save_buf_size:0:"data_files/server5.crt"
Session serialisation, save buffer size: small ticket, cert
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
ssl_serialise_session_save_buf_size:42:"data_files/server5.crt"
Session serialisation, save buffer size: large ticket, cert
depends_on:MBEDTLS_SSL_SESSION_TICKETS:MBEDTLS_SSL_CLI_C:MBEDTLS_X509_USE_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C
ssl_serialise_session_save_buf_size:1023:"data_files/server5.crt"

View file

@ -712,3 +712,39 @@ exit:
mbedtls_free( buf2 ); mbedtls_free( buf2 );
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */
void ssl_serialise_session_save_buf_size( int ticket_len, char *crt_file )
{
mbedtls_ssl_session session;
unsigned char *buf = NULL;
size_t good_len, bad_len, test_len;
/*
* Test that session_save() fails cleanly on small buffers
*/
mbedtls_ssl_session_init( &session );
/* Prepare dummy session and get serialised size */
ssl_populate_session( &session, ticket_len, crt_file );
TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &good_len )
== MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
/* Try all possible bad lengths */
for( bad_len = 1; bad_len < good_len; bad_len++ )
{
/* Allocate exact size so that asan/valgrind can detect any overwrite */
mbedtls_free( buf );
TEST_ASSERT( ( buf = mbedtls_calloc( 1, bad_len ) ) != NULL );
TEST_ASSERT( mbedtls_ssl_session_save( &session, buf, bad_len,
&test_len )
== MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
TEST_ASSERT( test_len == good_len );
}
exit:
mbedtls_ssl_session_free( &session );
mbedtls_free( buf );
}
/* END_CASE */