mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-27 01:35:27 +00:00
Merge pull request #2937 from gilles-peskine-arm/memory_buffer_alloc-fatal-pass-2.7
Backport 2.7: Clarify test descriptions in test_suite_memory_buffer_alloc
This commit is contained in:
commit
df1b3e54c7
|
@ -16,8 +16,8 @@ memory_buffer_alloc_free_alloc:100:64:100:100:0:0:0:1:200:0
|
||||||
Memory buffer alloc - Out of Memory test
|
Memory buffer alloc - Out of Memory test
|
||||||
memory_buffer_alloc_oom_test:
|
memory_buffer_alloc_oom_test:
|
||||||
|
|
||||||
Memory buffer small buffer
|
Memory buffer: heap too small (header verification should fail)
|
||||||
memory_buffer_small_buffer:
|
memory_buffer_heap_too_small:
|
||||||
|
|
||||||
Memory buffer underalloc
|
Memory buffer: attempt to allocate SIZE_MAX
|
||||||
memory_buffer_underalloc:
|
memory_buffer_underalloc:
|
||||||
|
|
|
@ -29,7 +29,7 @@ void mbedtls_memory_buffer_alloc_self_test( )
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
/* BEGIN_CASE */
|
||||||
void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||||
int d_bytes,
|
int d_bytes,
|
||||||
int free_a, int free_b, int free_c,
|
int free_a, int free_b, int free_c,
|
||||||
|
@ -40,8 +40,11 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||||
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL, *ptr_d = NULL,
|
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL, *ptr_d = NULL,
|
||||||
*ptr_e = NULL, *ptr_f = NULL;
|
*ptr_e = NULL, *ptr_f = NULL;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
size_t reported_blocks;
|
size_t reported_blocks;
|
||||||
size_t allocated_bytes = 0, reported_bytes;
|
size_t reported_bytes;
|
||||||
|
#endif
|
||||||
|
size_t allocated_bytes = 0;
|
||||||
|
|
||||||
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
||||||
|
|
||||||
|
@ -79,8 +82,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||||
allocated_bytes += d_bytes * sizeof(char);
|
allocated_bytes += d_bytes * sizeof(char);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||||
TEST_ASSERT( reported_bytes == allocated_bytes );
|
TEST_ASSERT( reported_bytes == allocated_bytes );
|
||||||
|
#endif
|
||||||
|
|
||||||
if( free_a )
|
if( free_a )
|
||||||
{
|
{
|
||||||
|
@ -118,8 +123,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||||
allocated_bytes -= d_bytes * sizeof(char);
|
allocated_bytes -= d_bytes * sizeof(char);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||||
TEST_ASSERT( reported_bytes == allocated_bytes );
|
TEST_ASSERT( reported_bytes == allocated_bytes );
|
||||||
|
#endif
|
||||||
|
|
||||||
if( e_bytes > 0 )
|
if( e_bytes > 0 )
|
||||||
{
|
{
|
||||||
|
@ -179,8 +186,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||||
ptr_f = NULL;
|
ptr_f = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||||
TEST_ASSERT( reported_bytes == 0 );
|
TEST_ASSERT( reported_bytes == 0 );
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
||||||
|
|
||||||
|
@ -189,12 +198,14 @@ exit:
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
/* BEGIN_CASE */
|
||||||
void memory_buffer_alloc_oom_test( )
|
void memory_buffer_alloc_oom_test( )
|
||||||
{
|
{
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL;
|
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL;
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
size_t reported_blocks, reported_bytes;
|
size_t reported_blocks, reported_bytes;
|
||||||
|
#endif
|
||||||
|
|
||||||
(void)ptr_c;
|
(void)ptr_c;
|
||||||
|
|
||||||
|
@ -211,8 +222,10 @@ void memory_buffer_alloc_oom_test()
|
||||||
ptr_c = mbedtls_calloc( 431, sizeof(char) );
|
ptr_c = mbedtls_calloc( 431, sizeof(char) );
|
||||||
TEST_ASSERT( ptr_c == NULL );
|
TEST_ASSERT( ptr_c == NULL );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||||
TEST_ASSERT( reported_bytes >= 864 && reported_bytes <= sizeof(buf) );
|
TEST_ASSERT( reported_bytes >= 864 && reported_bytes <= sizeof(buf) );
|
||||||
|
#endif
|
||||||
|
|
||||||
mbedtls_free( ptr_a );
|
mbedtls_free( ptr_a );
|
||||||
ptr_a = NULL;
|
ptr_a = NULL;
|
||||||
|
@ -222,8 +235,10 @@ void memory_buffer_alloc_oom_test()
|
||||||
ptr_b = NULL;
|
ptr_b = NULL;
|
||||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||||
TEST_ASSERT( reported_bytes == 0 );
|
TEST_ASSERT( reported_bytes == 0 );
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
||||||
|
|
||||||
|
@ -232,17 +247,20 @@ exit:
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
/* BEGIN_CASE */
|
||||||
void memory_buffer_small_buffer( )
|
void memory_buffer_heap_too_small( )
|
||||||
{
|
{
|
||||||
unsigned char buf[1];
|
unsigned char buf[1];
|
||||||
|
|
||||||
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
||||||
|
/* With MBEDTLS_MEMORY_DEBUG enabled, this prints a message
|
||||||
|
* "FATAL: verification of first header failed".
|
||||||
|
*/
|
||||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() != 0 );
|
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() != 0 );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
/* BEGIN_CASE */
|
||||||
void memory_buffer_underalloc( )
|
void memory_buffer_underalloc( )
|
||||||
{
|
{
|
||||||
unsigned char buf[100];
|
unsigned char buf[100];
|
||||||
|
|
Loading…
Reference in a new issue