diff --git a/test/simple-memory-corruption/.gitignore b/test/simple-memory-corruption/.gitignore index 97915d1..0f7c7a4 100644 --- a/test/simple-memory-corruption/.gitignore +++ b/test/simple-memory-corruption/.gitignore @@ -28,4 +28,6 @@ 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 index 49a3015..5cd476c 100644 --- a/test/simple-memory-corruption/Makefile +++ b/test/simple-memory-corruption/Makefile @@ -42,7 +42,9 @@ EXECUTABLES := \ invalid_malloc_usable_size_small \ invalid_malloc_usable_size_small_quarantine \ malloc_object_size \ - malloc_object_size_offset + malloc_object_size_offset \ + invalid_malloc_object_size_small \ + invalid_malloc_object_size_small_quarantine all: $(EXECUTABLES) diff --git a/test/simple-memory-corruption/invalid_malloc_object_size_small.c b/test/simple-memory-corruption/invalid_malloc_object_size_small.c new file mode 100644 index 0000000..f1796a3 --- /dev/null +++ b/test/simple-memory-corruption/invalid_malloc_object_size_small.c @@ -0,0 +1,14 @@ +#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 new file mode 100644 index 0000000..ac8a7e8 --- /dev/null +++ b/test/simple-memory-corruption/invalid_malloc_object_size_small_quarantine.c @@ -0,0 +1,14 @@ +#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/test_smc.py b/test/simple-memory-corruption/test_smc.py index 83aa247..4122d4a 100644 --- a/test/simple-memory-corruption/test_smc.py +++ b/test/simple-memory-corruption/test_smc.py @@ -186,8 +186,24 @@ class TestSimpleMemoryCorruption(unittest.TestCase): self.assertEqual(returncode, 0) def test_malloc_object_size_offset(self): - _stdout, _stderr, returncode = self.run_test("malloc_object_size_offset") + _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()