mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2024-12-29 09:21:19 +00:00
Basic functional test for memory poisoning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
0bdb6dc079
commit
479a1944e8
23
tests/suites/test_suite_test_helpers.data
Normal file
23
tests/suites/test_suite_test_helpers.data
Normal file
@ -0,0 +1,23 @@
|
||||
Memory poison+unpoison: offset=0 len=42
|
||||
memory_poison_unpoison:0:42
|
||||
|
||||
Memory poison+unpoison: offset=0 len=1
|
||||
memory_poison_unpoison:0:1
|
||||
|
||||
Memory poison+unpoison: offset=0 len=2
|
||||
memory_poison_unpoison:0:2
|
||||
|
||||
Memory poison+unpoison: offset=1 len=1
|
||||
memory_poison_unpoison:1:1
|
||||
|
||||
Memory poison+unpoison: offset=1 len=2
|
||||
memory_poison_unpoison:1:2
|
||||
|
||||
Memory poison+unpoison: offset=7 len=1
|
||||
memory_poison_unpoison:7:1
|
||||
|
||||
Memory poison+unpoison: offset=7 len=2
|
||||
memory_poison_unpoison:7:2
|
||||
|
||||
Memory poison+unpoison: offset=0 len=0
|
||||
memory_poison_unpoison:0:0
|
40
tests/suites/test_suite_test_helpers.function
Normal file
40
tests/suites/test_suite_test_helpers.function
Normal file
@ -0,0 +1,40 @@
|
||||
/* BEGIN_HEADER */
|
||||
|
||||
/* Test some parts of the test framework. */
|
||||
|
||||
#include <test/helpers.h>
|
||||
#include <test/memory.h>
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES */
|
||||
|
||||
/* END_DEPENDENCIES */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
/* Test that poison+unpoison leaves the memory accessible. */
|
||||
/* We can't test that poisoning makes the memory inaccessible:
|
||||
* there's no sane way to catch an Asan/Valgrind complaint.
|
||||
* That negative testing is done in programs/test/metatest.c. */
|
||||
void memory_poison_unpoison(int align, int size)
|
||||
{
|
||||
unsigned char *buf = NULL;
|
||||
const size_t buffer_size = align + size;
|
||||
TEST_CALLOC(buf, buffer_size);
|
||||
|
||||
for (size_t i = 0; i < buffer_size; i++) {
|
||||
buf[i] = (unsigned char) (i & 0xff);
|
||||
}
|
||||
|
||||
const unsigned char *start = buf == NULL ? NULL : buf + align;
|
||||
mbedtls_test_memory_poison(start, (size_t) size);
|
||||
mbedtls_test_memory_unpoison(start, (size_t) size);
|
||||
|
||||
for (size_t i = 0; i < buffer_size; i++) {
|
||||
TEST_EQUAL(buf[i], (unsigned char) (i & 0xff));
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_free(buf);
|
||||
}
|
||||
/* END_CASE */
|
Loading…
Reference in New Issue
Block a user