diff --git a/tests/suites/test_suite_bignum.function b/tests/suites/test_suite_bignum.function index c90f1bbbb..2305f488c 100644 --- a/tests/suites/test_suite_bignum.function +++ b/tests/suites/test_suite_bignum.function @@ -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) { diff --git a/tests/suites/test_suite_bignum.misc.data b/tests/suites/test_suite_bignum.misc.data index 9d068f146..c53e42a8f 100644 --- a/tests/suites/test_suite_bignum.misc.data +++ b/tests/suites/test_suite_bignum.misc.data @@ -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"