mbedtls/tests/suites
Manuel Pégourié-Gonnard a3d831b9e6 Add test for session_load() from small buffers
This uncovered a bug that led to a double-free (in practice, in general could
be free() on any invalid value): initially the session structure is loaded
with `memcpy()` which copies the previous values of pointers peer_cert and
ticket to heap-allocated buffers (or any other value if the input is
attacker-controlled). Now if we exit before we got a chance to replace those
invalid values with valid ones (for example because the input buffer is too
small, or because the second malloc() failed), then the next call to
session_free() is going to call free() on invalid pointers.

This bug is fixed in this commit by always setting the pointers to NULL right
after they've been read from the serialised state, so that the invalid values
can never be used.

(An alternative would be to NULL-ify them when writing, which was rejected
mostly because we need to do it when reading anyway (as the consequences of
free(invalid) are too severe to take any risk), so doing it when writing as
well is redundant and a waste of code size.)

Also, while thinking about what happens in case of errors, it became apparent
to me that it was bad practice to leave the session structure in an
half-initialised state and rely on the caller to call session_free(), so this
commit also ensures we always clear the structure when loading failed.
2019-08-23 12:48:41 +03:00
..
helpers.function Add TEST_ASSUME macro to allow skipping tests at runtime 2019-07-05 13:39:09 +01:00
host_test.function Add TEST_ASSUME macro to allow skipping tests at runtime 2019-07-05 13:39:09 +01:00
main_test.function Add TEST_ASSUME macro to allow skipping tests at runtime 2019-07-05 13:39:09 +01:00
target_test.function Merge remote-tracking branch 'origin/pr/2660' into development 2019-07-11 16:17:38 +01:00
test_suite_debug.data Update certificates to expire in 2029 2019-07-10 16:46:34 +03:00
test_suite_debug.function Rename HexParam_t -> data_t for consistent coding style 2018-08-06 11:42:06 +01:00
test_suite_error.data The Great Renaming 2015-04-08 13:25:31 +02:00
test_suite_error.function Intermediate hexify out change 2018-08-06 11:40:57 +01:00
test_suite_ssl.data Add test for session_load() from small buffers 2019-08-23 12:48:41 +03:00
test_suite_ssl.function Add test for session_load() from small buffers 2019-08-23 12:48:41 +03:00
test_suite_version.data Update library version to 2.17.0 2019-03-19 16:12:55 +00:00
test_suite_version.function Intermediate hexify out change 2018-08-06 11:40:57 +01:00
test_suite_x509parse.data Update certificates to expire in 2029 2019-07-10 16:46:34 +03:00
test_suite_x509parse.function Add test cases exercising successful verification of MD2/MD4/MD5 CRT 2019-06-03 14:45:21 +01:00
test_suite_x509write.data Update certificates to expire in 2029 2019-07-10 16:46:34 +03:00
test_suite_x509write.function Add tests for (named) bitstring to suite_asn1write 2019-02-28 09:36:30 +00:00