test_suite_bignum: add test function: mpi_zero_length_buffer_is_null()

The goal is to test all the bignum's functions that accept a buffer
and its length and verify that they do not crash if a NULL pointer
is passed in as buffer and 0 length is specified.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-01-30 14:40:31 +01:00
parent 779a1a5b20
commit f988f95b9a
2 changed files with 23 additions and 0 deletions

View file

@ -143,6 +143,26 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE */
void mpi_zero_length_buffer_is_null()
{
mbedtls_mpi X;
size_t olen;
mbedtls_mpi_init(&X);
/* Simply test that the following functions do not crash when a NULL buffer
* pointer and 0 length is passed. We don't care much about the return value. */
TEST_EQUAL(mbedtls_mpi_read_binary(&X, NULL, 0), 0);
TEST_EQUAL(mbedtls_mpi_read_binary_le(&X, NULL, 0), 0);
TEST_EQUAL(mbedtls_mpi_write_string(&X, 16, NULL, 0, &olen), MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL);
TEST_EQUAL(mbedtls_mpi_write_binary(&X, NULL, 0), 0);
exit:
mbedtls_mpi_free(&X);
}
/* END_CASE */
/* BEGIN_CASE */
void mpi_read_binary(data_t *buf, char *input_A)
{

View file

@ -82,6 +82,9 @@ mpi_read_write_string:16:"":2:"0":4:0:0
Test mpi_write_string #10 (Negative hex with odd number of digits)
mpi_read_write_string:16:"-1":16:"":3:0:MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL
Provide NULL buffer with 0 length
mpi_zero_length_buffer_is_null
Base test mbedtls_mpi_read_binary #1
mpi_read_binary:"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424":"0941379D00FED1491FE15DF284DFDE4A142F68AA8D412023195CEE66883E6290FFE703F4EA5963BF212713CEE46B107C09182B5EDCD955ADAC418BF4918E2889AF48E1099D513830CEC85C26AC1E158B52620E33BA8692F893EFBB2F958B4424"