From 903cba5a84952a84ee2d36ed00d7ca1b2d9b8604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 27 Sep 2023 16:33:18 +0200 Subject: [PATCH] test: add regression test for missing init() in realloc() --- test/.gitignore | 1 + test/Makefile | 3 ++- test/realloc_init.c | 33 +++++++++++++++++++++++++++++++++ test/test_smc.py | 4 ++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/realloc_init.c diff --git a/test/.gitignore b/test/.gitignore index f26606c..d37a6a7 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -40,4 +40,5 @@ overflow_small_1_byte overflow_small_8_byte uninitialized_read_large uninitialized_read_small +realloc_init __pycache__/ diff --git a/test/Makefile b/test/Makefile index add62ae..0eb3921 100644 --- a/test/Makefile +++ b/test/Makefile @@ -66,7 +66,8 @@ EXECUTABLES := \ malloc_object_size_offset \ invalid_malloc_object_size_small \ invalid_malloc_object_size_small_quarantine \ - impossibly_large_malloc + impossibly_large_malloc \ + realloc_init all: $(EXECUTABLES) diff --git a/test/realloc_init.c b/test/realloc_init.c new file mode 100644 index 0000000..01ec573 --- /dev/null +++ b/test/realloc_init.c @@ -0,0 +1,33 @@ +#include +#include + +static void *thread_func(void *arg) { + arg = realloc(arg, 1024); + if (!arg) { + exit(EXIT_FAILURE); + } + + free(arg); + + return NULL; +} + +int main(void) { + void *mem = realloc(NULL, 12); + if (!mem) { + return EXIT_FAILURE; + } + + pthread_t thread; + int r = pthread_create(&thread, NULL, thread_func, mem); + if (r != 0) { + return EXIT_FAILURE; + } + + r = pthread_join(thread, NULL); + if (r != 0) { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/test/test_smc.py b/test/test_smc.py index 23179ae..170278e 100644 --- a/test/test_smc.py +++ b/test/test_smc.py @@ -233,6 +233,10 @@ class TestSimpleMemoryCorruption(unittest.TestCase): "uninitialized_read_large") self.assertEqual(returncode, 0) + def test_realloc_init(self): + _stdout, _stderr, returncode = self.run_test( + "realloc_init") + self.assertEqual(returncode, 0) if __name__ == '__main__': unittest.main()