mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-05-30 04:04:51 +03:00
Move the overallocation test to test suites
This way the compiler does not complain about an overly large allocation made. Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
parent
8ca66a0795
commit
f35490e7af
@ -81,10 +81,7 @@ static int calloc_self_test(int verbose)
|
|||||||
unsigned int buffer_4_size = 4097; /* Allocate more than the usual page size */
|
unsigned int buffer_4_size = 4097; /* Allocate more than the usual page size */
|
||||||
unsigned char *buffer3 = mbedtls_calloc(buffer_3_size, 1);
|
unsigned char *buffer3 = mbedtls_calloc(buffer_3_size, 1);
|
||||||
unsigned char *buffer4 = mbedtls_calloc(buffer_4_size, 1);
|
unsigned char *buffer4 = mbedtls_calloc(buffer_4_size, 1);
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Walloc-size-larger-than="
|
|
||||||
unsigned char *buffer5 = mbedtls_calloc(SIZE_MAX/2, SIZE_MAX/2);
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
if (empty1 == NULL && empty2 == NULL) {
|
if (empty1 == NULL && empty2 == NULL) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
mbedtls_printf(" CALLOC(0,1): passed (NULL)\n");
|
mbedtls_printf(" CALLOC(0,1): passed (NULL)\n");
|
||||||
@ -179,13 +176,6 @@ static int calloc_self_test(int verbose)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer5 != NULL) {
|
|
||||||
++failures;
|
|
||||||
if (verbose) {
|
|
||||||
mbedtls_printf(" CALLOC(SIZE_MAX/2, SIZE_MAX/2): failed (returned a valid pointer)\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
mbedtls_printf("\n");
|
mbedtls_printf("\n");
|
||||||
}
|
}
|
||||||
@ -195,7 +185,6 @@ static int calloc_self_test(int verbose)
|
|||||||
mbedtls_free(buffer2);
|
mbedtls_free(buffer2);
|
||||||
mbedtls_free(buffer3);
|
mbedtls_free(buffer3);
|
||||||
mbedtls_free(buffer4);
|
mbedtls_free(buffer4);
|
||||||
mbedtls_free(buffer5);
|
|
||||||
return failures;
|
return failures;
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SELF_TEST */
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
|
@ -65,3 +65,6 @@ mbedtls_debug_print_crt:"data_files/server1.crt":"MyFile":999:"PREFIX_":"MyFile(
|
|||||||
Debug print certificate #2 (EC)
|
Debug print certificate #2 (EC)
|
||||||
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_BASE64_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_SHA256_C
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_BASE64_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP384R1_ENABLED:MBEDTLS_SHA256_C
|
||||||
mbedtls_debug_print_crt:"data_files/test-ca2.crt":"MyFile":999:"PREFIX_":"MyFile(0999)\: PREFIX_ #1\:\nMyFile(0999)\: cert. version \: 3\nMyFile(0999)\: serial number \: C1\:43\:E2\:7E\:62\:43\:CC\:E8\nMyFile(0999)\: issuer name \: C=NL, O=PolarSSL, CN=Polarssl Test EC CA\nMyFile(0999)\: subject name \: C=NL, O=PolarSSL, CN=Polarssl Test EC CA\nMyFile(0999)\: issued on \: 2019-02-10 14\:44\:00\nMyFile(0999)\: expires on \: 2029-02-10 14\:44\:00\nMyFile(0999)\: signed using \: ECDSA with SHA256\nMyFile(0999)\: EC key size \: 384 bits\nMyFile(0999)\: basic constraints \: CA=true\nMyFile(0999)\: value of 'crt->eckey.Q(X)' (384 bits) is\:\nMyFile(0999)\: c3 da 2b 34 41 37 58 2f 87 56 fe fc 89 ba 29 43\nMyFile(0999)\: 4b 4e e0 6e c3 0e 57 53 33 39 58 d4 52 b4 91 95\nMyFile(0999)\: 39 0b 23 df 5f 17 24 62 48 fc 1a 95 29 ce 2c 2d\nMyFile(0999)\: value of 'crt->eckey.Q(Y)' (384 bits) is\:\nMyFile(0999)\: 87 c2 88 52 80 af d6 6a ab 21 dd b8 d3 1c 6e 58\nMyFile(0999)\: b8 ca e8 b2 69 8e f3 41 ad 29 c3 b4 5f 75 a7 47\nMyFile(0999)\: 6f d5 19 29 55 69 9a 53 3b 20 b4 66 16 60 33 1e\n"
|
mbedtls_debug_print_crt:"data_files/test-ca2.crt":"MyFile":999:"PREFIX_":"MyFile(0999)\: PREFIX_ #1\:\nMyFile(0999)\: cert. version \: 3\nMyFile(0999)\: serial number \: C1\:43\:E2\:7E\:62\:43\:CC\:E8\nMyFile(0999)\: issuer name \: C=NL, O=PolarSSL, CN=Polarssl Test EC CA\nMyFile(0999)\: subject name \: C=NL, O=PolarSSL, CN=Polarssl Test EC CA\nMyFile(0999)\: issued on \: 2019-02-10 14\:44\:00\nMyFile(0999)\: expires on \: 2029-02-10 14\:44\:00\nMyFile(0999)\: signed using \: ECDSA with SHA256\nMyFile(0999)\: EC key size \: 384 bits\nMyFile(0999)\: basic constraints \: CA=true\nMyFile(0999)\: value of 'crt->eckey.Q(X)' (384 bits) is\:\nMyFile(0999)\: c3 da 2b 34 41 37 58 2f 87 56 fe fc 89 ba 29 43\nMyFile(0999)\: 4b 4e e0 6e c3 0e 57 53 33 39 58 d4 52 b4 91 95\nMyFile(0999)\: 39 0b 23 df 5f 17 24 62 48 fc 1a 95 29 ce 2c 2d\nMyFile(0999)\: value of 'crt->eckey.Q(Y)' (384 bits) is\:\nMyFile(0999)\: 87 c2 88 52 80 af d6 6a ab 21 dd b8 d3 1c 6e 58\nMyFile(0999)\: b8 ca e8 b2 69 8e f3 41 ad 29 c3 b4 5f 75 a7 47\nMyFile(0999)\: 6f d5 19 29 55 69 9a 53 3b 20 b4 66 16 60 33 1e\n"
|
||||||
|
|
||||||
|
Check mbedtls_calloc overallocation
|
||||||
|
check_mbedtls_calloc_overallocation:SIZE_MAX/2:SIZE_MAX/2
|
||||||
|
@ -195,3 +195,15 @@ exit:
|
|||||||
mbedtls_ssl_config_free(&conf);
|
mbedtls_ssl_config_free(&conf);
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void check_mbedtls_calloc_overallocation(int num, int size)
|
||||||
|
{
|
||||||
|
unsigned char *buf;
|
||||||
|
buf = mbedtls_calloc((size_t) num, (size_t) size);
|
||||||
|
TEST_ASSERT(buf == NULL);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_free(buf);
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user