mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-04-20 06:20:20 +02:00
Add a test for slab canaries
This commit is contained in:
parent
9142a9376b
commit
da73b28162
3 changed files with 31 additions and 1 deletions
|
@ -46,7 +46,8 @@ EXECUTABLES := \
|
||||||
malloc_object_size_offset \
|
malloc_object_size_offset \
|
||||||
invalid_malloc_object_size_small \
|
invalid_malloc_object_size_small \
|
||||||
invalid_malloc_object_size_small_quarantine \
|
invalid_malloc_object_size_small_quarantine \
|
||||||
impossibly_large_malloc
|
impossibly_large_malloc \
|
||||||
|
canary_leak
|
||||||
|
|
||||||
all: $(EXECUTABLES)
|
all: $(EXECUTABLES)
|
||||||
|
|
||||||
|
|
24
test/simple-memory-corruption/canary_leak.c
Normal file
24
test/simple-memory-corruption/canary_leak.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../test_util.h"
|
||||||
|
|
||||||
|
#define CANARY_SIZE 8
|
||||||
|
|
||||||
|
// Check that the slab canary can't be leaked with a C-string function.
|
||||||
|
OPTNONE int main(void) {
|
||||||
|
char leaked_str_canary[CANARY_SIZE] = {0};
|
||||||
|
char leaked_canary[CANARY_SIZE] = {0};
|
||||||
|
char *p = malloc(8);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strncpy(leaked_str_canary, p + 8, CANARY_SIZE);
|
||||||
|
memcpy(leaked_canary, p + 8, CANARY_SIZE);
|
||||||
|
if (!memcmp(leaked_canary, leaked_str_canary, CANARY_SIZE)) {
|
||||||
|
free(p);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -211,6 +211,11 @@ class TestSimpleMemoryCorruption(unittest.TestCase):
|
||||||
"impossibly_large_malloc")
|
"impossibly_large_malloc")
|
||||||
self.assertEqual(returncode, 0)
|
self.assertEqual(returncode, 0)
|
||||||
|
|
||||||
|
def test_canary_leak(self):
|
||||||
|
_stdout, stderr, returncode = self.run_test(
|
||||||
|
"canary_leak")
|
||||||
|
self.assertEqual(returncode, 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue