diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index d7468c3..0000000 --- a/test/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -large_array_growth -mallinfo -mallinfo2 -malloc_info -offset diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 9e16557..0000000 --- a/test/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -CONFIG_SLAB_CANARY := true -CONFIG_EXTENDED_SIZE_CLASSES := true - -ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false)) - $(error CONFIG_SLAB_CANARY must be true or false) -endif - -LDLIBS := -lpthread - -CPPFLAGS += \ - -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) \ - -DCONFIG_EXTENDED_SIZE_CLASSES=$(CONFIG_EXTENDED_SIZE_CLASSES) - -EXECUTABLES := \ - offset \ - mallinfo \ - mallinfo2 \ - malloc_info \ - large_array_growth - -all: $(EXECUTABLES) - make -C simple-memory-corruption - -clean: - rm -f $(EXECUTABLES) diff --git a/test/large_array_growth.c b/test/large_array_growth.c deleted file mode 100644 index 09f89c5..0000000 --- a/test/large_array_growth.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -#include "test_util.h" - -OPTNONE int main(void) { - void *p = NULL; - size_t size = 256 * 1024; - - for (unsigned i = 0; i < 20; i++) { - p = realloc(p, size); - if (!p) { - return 1; - } - memset(p, 'a', size); - size = size * 3 / 2; - } -} diff --git a/test/mallinfo.c b/test/mallinfo.c deleted file mode 100644 index e5df5a8..0000000 --- a/test/mallinfo.c +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include - -#include "test_util.h" - -static void print_mallinfo(void) { - struct mallinfo info = mallinfo(); - printf("mallinfo:\n"); - printf("arena: %zu\n", (size_t)info.arena); - printf("ordblks: %zu\n", (size_t)info.ordblks); - printf("smblks: %zu\n", (size_t)info.smblks); - printf("hblks: %zu\n", (size_t)info.hblks); - printf("hblkhd: %zu\n", (size_t)info.hblkhd); - printf("usmblks: %zu\n", (size_t)info.usmblks); - printf("fsmblks: %zu\n", (size_t)info.fsmblks); - printf("uordblks: %zu\n", (size_t)info.uordblks); - printf("fordblks: %zu\n", (size_t)info.fordblks); - printf("keepcost: %zu\n", (size_t)info.keepcost); -} - -OPTNONE int main(void) { - void *a[4]; - - a[0] = malloc(1024 * 1024 * 1024); - a[1] = malloc(16); - a[2] = malloc(32); - a[3] = malloc(64); - - print_mallinfo(); - - free(a[0]); - free(a[1]); - free(a[2]); - free(a[3]); - - printf("\n"); - print_mallinfo(); -} diff --git a/test/mallinfo2.c b/test/mallinfo2.c deleted file mode 100644 index 0f486d5..0000000 --- a/test/mallinfo2.c +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include - -#include "test_util.h" - -static void print_mallinfo2(void) { - struct mallinfo2 info = mallinfo2(); - printf("mallinfo2:\n"); - printf("arena: %zu\n", (size_t)info.arena); - printf("ordblks: %zu\n", (size_t)info.ordblks); - printf("smblks: %zu\n", (size_t)info.smblks); - printf("hblks: %zu\n", (size_t)info.hblks); - printf("hblkhd: %zu\n", (size_t)info.hblkhd); - printf("usmblks: %zu\n", (size_t)info.usmblks); - printf("fsmblks: %zu\n", (size_t)info.fsmblks); - printf("uordblks: %zu\n", (size_t)info.uordblks); - printf("fordblks: %zu\n", (size_t)info.fordblks); - printf("keepcost: %zu\n", (size_t)info.keepcost); -} - -OPTNONE int main(void) { - void *a[4]; - - a[0] = malloc(1024 * 1024 * 1024); - a[1] = malloc(16); - a[2] = malloc(32); - a[3] = malloc(64); - - print_mallinfo2(); - - free(a[0]); - free(a[1]); - free(a[2]); - free(a[3]); - - printf("\n"); - print_mallinfo2(); -} diff --git a/test/malloc_info.c b/test/malloc_info.c deleted file mode 100644 index 62a315f..0000000 --- a/test/malloc_info.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -#include - -#include "test_util.h" - -OPTNONE static void leak_memory(void) { - (void)malloc(1024 * 1024 * 1024); - (void)malloc(16); - (void)malloc(32); - (void)malloc(4096); -} - -static void *do_work(void *p) { - leak_memory(); - return NULL; -} - -int main(void) { - pthread_t thread[4]; - for (int i = 0; i < 4; i++) { - pthread_create(&thread[i], NULL, do_work, NULL); - } - for (int i = 0; i < 4; i++) { - pthread_join(thread[i], NULL); - } - - malloc_info(0, stdout); -} diff --git a/test/offset.c b/test/offset.c deleted file mode 100644 index af14f5c..0000000 --- a/test/offset.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include - -static size_t size_classes[] = { - /* large */ 4 * 1024 * 1024, - /* 0 */ 0, - /* 16 */ 16, 32, 48, 64, 80, 96, 112, 128, - /* 32 */ 160, 192, 224, 256, - /* 64 */ 320, 384, 448, 512, - /* 128 */ 640, 768, 896, 1024, - /* 256 */ 1280, 1536, 1792, 2048, - /* 512 */ 2560, 3072, 3584, 4096, - /* 1024 */ 5120, 6144, 7168, 8192, - /* 2048 */ 10240, 12288, 14336, 16384, -#if CONFIG_EXTENDED_SIZE_CLASSES - /* 4096 */ 20480, 24576, 28672, 32768, - /* 8192 */ 40960, 49152, 57344, 65536, - /* 16384 */ 81920, 98304, 114688, 131072, -#endif -}; - -#define N_SIZE_CLASSES (sizeof(size_classes) / sizeof(size_classes[0])) - -static const size_t canary_size = SLAB_CANARY ? sizeof(uint64_t) : 0; - -int main(void) { - for (unsigned i = 2; i < N_SIZE_CLASSES; i++) { - size_classes[i] -= canary_size; - } - - void *p[N_SIZE_CLASSES]; - for (unsigned i = 0; i < N_SIZE_CLASSES; i++) { - size_t size = size_classes[i]; - p[i] = malloc(size); - if (!p[i]) { - return 1; - } - void *q = malloc(size); - if (!q) { - return 1; - } - if (i != 0) { - printf("%zu to %zu: %zd\n", size_classes[i - 1], size, p[i] - p[i - 1]); - } - printf("%zu to %zu: %zd\n", size, size, q - p[i]); - } - return 0; -} diff --git a/test/simple-memory-corruption/.gitignore b/test/simple-memory-corruption/.gitignore deleted file mode 100644 index 0f7c7a4..0000000 --- a/test/simple-memory-corruption/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -delete_type_size_mismatch -double_free_large -double_free_large_delayed -double_free_small -double_free_small_delayed -eight_byte_overflow_large -eight_byte_overflow_small -invalid_free_protected -invalid_free_small_region -invalid_free_small_region_far -invalid_free_unprotected -read_after_free_large -read_after_free_small -read_zero_size -string_overflow -unaligned_free_large -unaligned_free_small -uninitialized_free -uninitialized_malloc_usable_size -uninitialized_realloc -write_after_free_large -write_after_free_large_reuse -write_after_free_small -write_after_free_small_reuse -write_zero_size -unaligned_malloc_usable_size_small -invalid_malloc_usable_size_small -invalid_malloc_usable_size_small_quarantine -malloc_object_size -malloc_object_size_offset -invalid_malloc_object_size_small -invalid_malloc_object_size_small_quarantine -__pycache__/ diff --git a/test/simple-memory-corruption/Makefile b/test/simple-memory-corruption/Makefile deleted file mode 100644 index 609677e..0000000 --- a/test/simple-memory-corruption/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -dir=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) - -CONFIG_SLAB_CANARY := true - -ifeq (,$(filter $(CONFIG_SLAB_CANARY),true false)) - $(error CONFIG_SLAB_CANARY must be true or false) -endif - -CFLAGS += -DSLAB_CANARY=$(CONFIG_SLAB_CANARY) - -LDLIBS := -lhardened_malloc - -LDFLAGS := -Wl,-L$(dir)../../,-R,$(dir)../../ - -EXECUTABLES := \ - double_free_large \ - double_free_large_delayed \ - double_free_small \ - double_free_small_delayed \ - unaligned_free_large \ - unaligned_free_small \ - read_after_free_large \ - read_after_free_small \ - write_after_free_large \ - write_after_free_large_reuse \ - write_after_free_small \ - write_after_free_small_reuse \ - read_zero_size \ - write_zero_size \ - invalid_free_protected \ - invalid_free_unprotected \ - invalid_free_small_region \ - invalid_free_small_region_far \ - uninitialized_free \ - uninitialized_realloc \ - uninitialized_malloc_usable_size \ - eight_byte_overflow_small \ - eight_byte_overflow_large \ - string_overflow \ - delete_type_size_mismatch \ - unaligned_malloc_usable_size_small \ - invalid_malloc_usable_size_small \ - invalid_malloc_usable_size_small_quarantine \ - malloc_object_size \ - malloc_object_size_offset \ - invalid_malloc_object_size_small \ - invalid_malloc_object_size_small_quarantine - -all: $(EXECUTABLES) - -clean: - rm -f $(EXECUTABLES) diff --git a/test/simple-memory-corruption/__init__.py b/test/simple-memory-corruption/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/simple-memory-corruption/delete_type_size_mismatch.cc b/test/simple-memory-corruption/delete_type_size_mismatch.cc deleted file mode 100644 index ffbb731..0000000 --- a/test/simple-memory-corruption/delete_type_size_mismatch.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#include "../test_util.h" - -struct foo { - uint64_t a, b, c, d; -}; - -OPTNONE int main(void) { - void *p = new char; - struct foo *c = (struct foo *)p; - delete c; - return 0; -} diff --git a/test/simple-memory-corruption/double_free_large.c b/test/simple-memory-corruption/double_free_large.c deleted file mode 100644 index 0c7412b..0000000 --- a/test/simple-memory-corruption/double_free_large.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - void *p = malloc(128 * 1024); - if (!p) { - return 1; - } - free(p); - free(p); - return 0; -} diff --git a/test/simple-memory-corruption/double_free_large_delayed.c b/test/simple-memory-corruption/double_free_large_delayed.c deleted file mode 100644 index f367590..0000000 --- a/test/simple-memory-corruption/double_free_large_delayed.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - void *p = malloc(128 * 1024); - if (!p) { - return 1; - } - void *q = malloc(128 * 1024); - if (!q) { - return 1; - } - free(p); - free(q); - free(p); - return 0; -} diff --git a/test/simple-memory-corruption/double_free_small.c b/test/simple-memory-corruption/double_free_small.c deleted file mode 100644 index 4635d36..0000000 --- a/test/simple-memory-corruption/double_free_small.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - void *p = malloc(16); - if (!p) { - return 1; - } - free(p); - free(p); - return 0; -} diff --git a/test/simple-memory-corruption/double_free_small_delayed.c b/test/simple-memory-corruption/double_free_small_delayed.c deleted file mode 100644 index acb4034..0000000 --- a/test/simple-memory-corruption/double_free_small_delayed.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - void *p = malloc(16); - if (!p) { - return 1; - } - void *q = malloc(16); - if (!q) { - return 1; - } - free(p); - free(q); - free(p); - return 0; -} diff --git a/test/simple-memory-corruption/eight_byte_overflow_large.c b/test/simple-memory-corruption/eight_byte_overflow_large.c deleted file mode 100644 index 3b8c8d3..0000000 --- a/test/simple-memory-corruption/eight_byte_overflow_large.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(256 * 1024); - if (!p) { - return 1; - } - *(p + 256 * 1024 + 7) = 0; - free(p); - return 0; -} diff --git a/test/simple-memory-corruption/eight_byte_overflow_small.c b/test/simple-memory-corruption/eight_byte_overflow_small.c deleted file mode 100644 index 0ac796b..0000000 --- a/test/simple-memory-corruption/eight_byte_overflow_small.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(8); - if (!p) { - return 1; - } - *(p + 8 + 7) = 0; - free(p); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_free_protected.c b/test/simple-memory-corruption/invalid_free_protected.c deleted file mode 100644 index ee81467..0000000 --- a/test/simple-memory-corruption/invalid_free_protected.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - free(malloc(16)); - char *p = mmap(NULL, 4096 * 16, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (p == MAP_FAILED) { - return 1; - } - free(p + 4096 * 8); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_free_small_region.c b/test/simple-memory-corruption/invalid_free_small_region.c deleted file mode 100644 index 4993724..0000000 --- a/test/simple-memory-corruption/invalid_free_small_region.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - char *q = p + 4096 * 4; - free(q); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_free_small_region_far.c b/test/simple-memory-corruption/invalid_free_small_region_far.c deleted file mode 100644 index c147ef3..0000000 --- a/test/simple-memory-corruption/invalid_free_small_region_far.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - char *q = p + 1024 * 1024 * 1024; - free(q); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_free_unprotected.c b/test/simple-memory-corruption/invalid_free_unprotected.c deleted file mode 100644 index c583c6b..0000000 --- a/test/simple-memory-corruption/invalid_free_unprotected.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - free(malloc(16)); - char *p = mmap(NULL, 4096 * 16, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (p == MAP_FAILED) { - return 1; - } - free(p + 4096 * 8); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_malloc_object_size_small.c b/test/simple-memory-corruption/invalid_malloc_object_size_small.c deleted file mode 100644 index f1796a3..0000000 --- a/test/simple-memory-corruption/invalid_malloc_object_size_small.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -size_t malloc_object_size(void *ptr); - -__attribute__((optimize(0))) -int main() { - char *p = malloc(16); - if (!p) { - return 1; - } - char *q = p + 4096 * 4; - malloc_object_size(q); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_malloc_object_size_small_quarantine.c b/test/simple-memory-corruption/invalid_malloc_object_size_small_quarantine.c deleted file mode 100644 index ac8a7e8..0000000 --- a/test/simple-memory-corruption/invalid_malloc_object_size_small_quarantine.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -size_t malloc_object_size(void *ptr); - -__attribute__((optimize(0))) -int main() { - void *p = malloc(16); - if (!p) { - return 1; - } - free(p); - malloc_object_size(p); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_malloc_usable_size_small.c b/test/simple-memory-corruption/invalid_malloc_usable_size_small.c deleted file mode 100644 index f200564..0000000 --- a/test/simple-memory-corruption/invalid_malloc_usable_size_small.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - char *q = p + 4096 * 4; - malloc_usable_size(q); - return 0; -} diff --git a/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c b/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c deleted file mode 100644 index ae0a8c6..0000000 --- a/test/simple-memory-corruption/invalid_malloc_usable_size_small_quarantine.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - void *p = malloc(16); - if (!p) { - return 1; - } - free(p); - malloc_usable_size(p); - return 0; -} diff --git a/test/simple-memory-corruption/malloc_object_size.c b/test/simple-memory-corruption/malloc_object_size.c deleted file mode 100644 index 04e6350..0000000 --- a/test/simple-memory-corruption/malloc_object_size.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -#include "../test_util.h" - -size_t malloc_object_size(void *ptr); - -OPTNONE int main(void) { - char *p = malloc(16); - size_t size = malloc_object_size(p); - return size != (SLAB_CANARY ? 24 : 32); -} diff --git a/test/simple-memory-corruption/malloc_object_size_offset.c b/test/simple-memory-corruption/malloc_object_size_offset.c deleted file mode 100644 index 2bc16b6..0000000 --- a/test/simple-memory-corruption/malloc_object_size_offset.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -#include "../test_util.h" - -size_t malloc_object_size(void *ptr); - -OPTNONE int main(void) { - char *p = malloc(16); - size_t size = malloc_object_size(p + 5); - return size != (SLAB_CANARY ? 19 : 27); -} diff --git a/test/simple-memory-corruption/read_after_free_large.c b/test/simple-memory-corruption/read_after_free_large.c deleted file mode 100644 index b5e611c..0000000 --- a/test/simple-memory-corruption/read_after_free_large.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(128 * 1024); - if (!p) { - return 1; - } - memset(p, 'a', 16); - free(p); - for (size_t i = 0; i < 128 * 1024; i++) { - printf("%x\n", p[i]); - } - return 0; -} diff --git a/test/simple-memory-corruption/read_after_free_small.c b/test/simple-memory-corruption/read_after_free_small.c deleted file mode 100644 index 7d53e5c..0000000 --- a/test/simple-memory-corruption/read_after_free_small.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - memset(p, 'a', 16); - free(p); - for (size_t i = 0; i < 16; i++) { - printf("%x\n", p[i]); - } - return 0; -} diff --git a/test/simple-memory-corruption/read_zero_size.c b/test/simple-memory-corruption/read_zero_size.c deleted file mode 100644 index 385f4d6..0000000 --- a/test/simple-memory-corruption/read_zero_size.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(0); - if (!p) { - return 1; - } - printf("%c\n", *p); - return 0; -} diff --git a/test/simple-memory-corruption/string_overflow.c b/test/simple-memory-corruption/string_overflow.c deleted file mode 100644 index 7f54a63..0000000 --- a/test/simple-memory-corruption/string_overflow.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - - size_t size = malloc_usable_size(p); - memset(p, 'a', size); - printf("overflow by %zu bytes\n", strlen(p) - size); - - return 0; -} diff --git a/test/simple-memory-corruption/test_smc.py b/test/simple-memory-corruption/test_smc.py deleted file mode 100644 index 30e3269..0000000 --- a/test/simple-memory-corruption/test_smc.py +++ /dev/null @@ -1,211 +0,0 @@ -import os -import subprocess -import unittest - - -class TestSimpleMemoryCorruption(unittest.TestCase): - - @classmethod - def setUpClass(self): - self.dir = os.path.dirname(os.path.realpath(__file__)) - - def run_test(self, test_name): - sub = subprocess.Popen(self.dir + "/" + test_name, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = sub.communicate() - return stdout, stderr, sub.returncode - - def test_delete_type_size_mismatch(self): - _stdout, stderr, returncode = self.run_test( - "delete_type_size_mismatch") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode( - "utf-8"), "fatal allocator error: sized deallocation mismatch (small)\n") - - def test_double_free_large_delayed(self): - _stdout, stderr, returncode = self.run_test( - "double_free_large_delayed") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid free\n") - - def test_double_free_large(self): - _stdout, stderr, returncode = self.run_test("double_free_large") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid free\n") - - def test_double_free_small_delayed(self): - _stdout, stderr, returncode = self.run_test( - "double_free_small_delayed") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: double free (quarantine)\n") - - def test_double_free_small(self): - _stdout, stderr, returncode = self.run_test("double_free_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: double free (quarantine)\n") - - def test_eight_byte_overflow_large(self): - _stdout, _stderr, returncode = self.run_test( - "eight_byte_overflow_large") - self.assertEqual(returncode, -11) - - def test_eight_byte_overflow_small(self): - _stdout, stderr, returncode = self.run_test( - "eight_byte_overflow_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: canary corrupted\n") - - def test_invalid_free_protected(self): - _stdout, stderr, returncode = self.run_test("invalid_free_protected") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid free\n") - - def test_invalid_free_small_region_far(self): - _stdout, stderr, returncode = self.run_test( - "invalid_free_small_region_far") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode( - "utf-8"), "fatal allocator error: invalid free within a slab yet to be used\n") - - def test_invalid_free_small_region(self): - _stdout, stderr, returncode = self.run_test( - "invalid_free_small_region") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: double free\n") - - def test_invalid_free_unprotected(self): - _stdout, stderr, returncode = self.run_test("invalid_free_unprotected") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid free\n") - - def test_invalid_malloc_usable_size_small_quarantene(self): - _stdout, stderr, returncode = self.run_test( - "invalid_malloc_usable_size_small_quarantine") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode( - "utf-8"), "fatal allocator error: invalid malloc_usable_size (quarantine)\n") - - def test_invalid_malloc_usable_size_small(self): - _stdout, stderr, returncode = self.run_test( - "invalid_malloc_usable_size_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode( - "utf-8"), "fatal allocator error: invalid malloc_usable_size\n") - - def test_read_after_free_large(self): - _stdout, _stderr, returncode = self.run_test("read_after_free_large") - self.assertEqual(returncode, -11) - - def test_read_after_free_small(self): - stdout, _stderr, returncode = self.run_test("read_after_free_small") - self.assertEqual(returncode, 0) - self.assertEqual(stdout.decode("utf-8"), - "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n") - - def test_read_zero_size(self): - _stdout, _stderr, returncode = self.run_test("read_zero_size") - self.assertEqual(returncode, -11) - - def test_string_overflow(self): - stdout, _stderr, returncode = self.run_test("string_overflow") - self.assertEqual(returncode, 0) - self.assertEqual(stdout.decode("utf-8"), "overflow by 0 bytes\n") - - def test_unaligned_free_large(self): - _stdout, stderr, returncode = self.run_test("unaligned_free_large") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid free\n") - - def test_unaligned_free_small(self): - _stdout, stderr, returncode = self.run_test("unaligned_free_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid unaligned free\n") - - def test_unaligned_malloc_usable_size_small(self): - _stdout, stderr, returncode = self.run_test( - "unaligned_malloc_usable_size_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid unaligned malloc_usable_size\n") - - def test_uninitialized_free(self): - _stdout, stderr, returncode = self.run_test("uninitialized_free") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid free\n") - - def test_uninitialized_malloc_usable_size(self): - _stdout, stderr, returncode = self.run_test( - "uninitialized_malloc_usable_size") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid malloc_usable_size\n") - - def test_uninitialized_realloc(self): - _stdout, stderr, returncode = self.run_test("uninitialized_realloc") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: invalid realloc\n") - - def test_write_after_free_large_reuse(self): - _stdout, _stderr, returncode = self.run_test( - "write_after_free_large_reuse") - self.assertEqual(returncode, -11) - - def test_write_after_free_large(self): - _stdout, _stderr, returncode = self.run_test("write_after_free_large") - self.assertEqual(returncode, -11) - - def test_write_after_free_small_reuse(self): - _stdout, stderr, returncode = self.run_test( - "write_after_free_small_reuse") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: detected write after free\n") - - def test_write_after_free_small(self): - _stdout, stderr, returncode = self.run_test("write_after_free_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode("utf-8"), - "fatal allocator error: detected write after free\n") - - def test_write_zero_size(self): - _stdout, _stderr, returncode = self.run_test("write_zero_size") - self.assertEqual(returncode, -11) - - def test_malloc_object_size(self): - _stdout, _stderr, returncode = self.run_test("malloc_object_size") - self.assertEqual(returncode, 0) - - def test_malloc_object_size_offset(self): - _stdout, _stderr, returncode = self.run_test( - "malloc_object_size_offset") - self.assertEqual(returncode, 0) - - def test_invalid_malloc_object_size_small(self): - _stdout, stderr, returncode = self.run_test( - "invalid_malloc_object_size_small") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode( - "utf-8"), "fatal allocator error: invalid malloc_object_size\n") - - def test_invalid_malloc_object_size_small_quarantine(self): - _stdout, stderr, returncode = self.run_test( - "invalid_malloc_object_size_small_quarantine") - self.assertEqual(returncode, -6) - self.assertEqual(stderr.decode( - "utf-8"), "fatal allocator error: invalid malloc_object_size (quarantine)\n") - - -if __name__ == '__main__': - unittest.main() diff --git a/test/simple-memory-corruption/unaligned_free_large.c b/test/simple-memory-corruption/unaligned_free_large.c deleted file mode 100644 index 10c7874..0000000 --- a/test/simple-memory-corruption/unaligned_free_large.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(128 * 1024); - if (!p) { - return 1; - } - free(p + 1); - return 0; -} diff --git a/test/simple-memory-corruption/unaligned_free_small.c b/test/simple-memory-corruption/unaligned_free_small.c deleted file mode 100644 index 1b2a7fc..0000000 --- a/test/simple-memory-corruption/unaligned_free_small.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - free(p + 1); - return 0; -} diff --git a/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c b/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c deleted file mode 100644 index 2bbbf8a..0000000 --- a/test/simple-memory-corruption/unaligned_malloc_usable_size_small.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(16); - if (!p) { - return 1; - } - malloc_usable_size(p + 1); - return 0; -} diff --git a/test/simple-memory-corruption/uninitialized_free.c b/test/simple-memory-corruption/uninitialized_free.c deleted file mode 100644 index 9e3c8b9..0000000 --- a/test/simple-memory-corruption/uninitialized_free.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - free((void *)1); - return 0; -} diff --git a/test/simple-memory-corruption/uninitialized_malloc_usable_size.c b/test/simple-memory-corruption/uninitialized_malloc_usable_size.c deleted file mode 100644 index d0644c4..0000000 --- a/test/simple-memory-corruption/uninitialized_malloc_usable_size.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - malloc_usable_size((void *)1); - return 0; -} diff --git a/test/simple-memory-corruption/uninitialized_realloc.c b/test/simple-memory-corruption/uninitialized_realloc.c deleted file mode 100644 index 4afc9de..0000000 --- a/test/simple-memory-corruption/uninitialized_realloc.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - void *p = realloc((void *)1, 16); - if (!p) { - return 1; - } - return 0; -} diff --git a/test/simple-memory-corruption/write_after_free_large.c b/test/simple-memory-corruption/write_after_free_large.c deleted file mode 100644 index d46cc0d..0000000 --- a/test/simple-memory-corruption/write_after_free_large.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(128 * 1024); - if (!p) { - return 1; - } - free(p); - p[64 * 1024 + 1] = 'a'; - return 0; -} diff --git a/test/simple-memory-corruption/write_after_free_large_reuse.c b/test/simple-memory-corruption/write_after_free_large_reuse.c deleted file mode 100644 index 3af225e..0000000 --- a/test/simple-memory-corruption/write_after_free_large_reuse.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(128 * 1024); - if (!p) { - return 1; - } - free(p); - char *q = malloc(128 * 1024); - p[64 * 1024 + 1] = 'a'; - return 0; -} diff --git a/test/simple-memory-corruption/write_after_free_small.c b/test/simple-memory-corruption/write_after_free_small.c deleted file mode 100644 index c78325e..0000000 --- a/test/simple-memory-corruption/write_after_free_small.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(128); - if (!p) { - return 1; - } - free(p); - - p[65] = 'a'; - - // trigger reuse of the allocation - for (size_t i = 0; i < 100000; i++) { - free(malloc(128)); - } - return 0; -} diff --git a/test/simple-memory-corruption/write_after_free_small_reuse.c b/test/simple-memory-corruption/write_after_free_small_reuse.c deleted file mode 100644 index 315407a..0000000 --- a/test/simple-memory-corruption/write_after_free_small_reuse.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(128); - if (!p) { - return 1; - } - free(p); - char *q = malloc(128); - - p[65] = 'a'; - - // trigger reuse of the allocation - for (size_t i = 0; i < 100000; i++) { - free(malloc(128)); - } - return 0; -} diff --git a/test/simple-memory-corruption/write_zero_size.c b/test/simple-memory-corruption/write_zero_size.c deleted file mode 100644 index 3687bf9..0000000 --- a/test/simple-memory-corruption/write_zero_size.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -#include "../test_util.h" - -OPTNONE int main(void) { - char *p = malloc(0); - if (!p) { - return 1; - } - *p = 5; - return 0; -} diff --git a/test/test_util.h b/test/test_util.h deleted file mode 100644 index d2d78a6..0000000 --- a/test/test_util.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef TEST_UTIL_H -#define TEST_UTIL_H - -#ifdef __clang__ -#define OPTNONE __attribute__((optnone)) -#else -#define OPTNONE __attribute__((optimize(0))) -#endif - -#endif