mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-21 19:20:56 +00:00
Change memory poisoning flag to a count
This allows unusually-nested memory poisoning to work correctly, since it keeps track of whether any buffers are still poisoned, rather than just disabling poisoning at the first call to the UNPOISON() macro. Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
parent
c2ab398d01
commit
fad038c501
@ -69,7 +69,7 @@
|
||||
* unset in the test wrappers so that calls to PSA functions from the library
|
||||
* do not poison memory.
|
||||
*/
|
||||
extern _Thread_local int mbedtls_test_memory_poisoning_enabled;
|
||||
extern _Thread_local unsigned int mbedtls_test_memory_poisoning_count;
|
||||
|
||||
/** Poison a memory area so that any attempt to read or write from it will
|
||||
* cause a runtime failure.
|
||||
@ -79,7 +79,7 @@ extern _Thread_local int mbedtls_test_memory_poisoning_enabled;
|
||||
void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size);
|
||||
#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) \
|
||||
do { \
|
||||
mbedtls_test_memory_poisoning_enabled = 1; \
|
||||
mbedtls_test_memory_poisoning_count++; \
|
||||
mbedtls_test_memory_poison(ptr, size); \
|
||||
} while (0)
|
||||
|
||||
@ -94,7 +94,7 @@ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size);
|
||||
#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \
|
||||
do { \
|
||||
mbedtls_test_memory_unpoison(ptr, size); \
|
||||
mbedtls_test_memory_poisoning_enabled = 0; \
|
||||
mbedtls_test_memory_poisoning_count--; \
|
||||
} while (0)
|
||||
|
||||
#else /* MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
|
||||
_Thread_local int mbedtls_test_memory_poisoning_enabled = 0;
|
||||
_Thread_local unsigned int mbedtls_test_memory_poisoning_count = 0;
|
||||
|
||||
static void align_for_asan(const unsigned char **p_ptr, size_t *p_size)
|
||||
{
|
||||
@ -39,7 +39,7 @@ static void align_for_asan(const unsigned char **p_ptr, size_t *p_size)
|
||||
|
||||
void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size)
|
||||
{
|
||||
if (!mbedtls_test_memory_poisoning_enabled) {
|
||||
if (mbedtls_test_memory_poisoning_count == 0) {
|
||||
return;
|
||||
}
|
||||
if (size == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user