From 5017500a4784942f50e9f6e6da13832bc19da11f Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 4 Sep 2018 09:06:23 -0400 Subject: [PATCH] add simple overflow tests --- test/simple-memory-corruption/Makefile | 2 ++ .../eight_byte_overflow_large.c | 12 ++++++++++++ .../eight_byte_overflow_small.c | 12 ++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/simple-memory-corruption/eight_byte_overflow_large.c create mode 100644 test/simple-memory-corruption/eight_byte_overflow_small.c diff --git a/test/simple-memory-corruption/Makefile b/test/simple-memory-corruption/Makefile index e3cf7e1..d3e35d7 100644 --- a/test/simple-memory-corruption/Makefile +++ b/test/simple-memory-corruption/Makefile @@ -18,6 +18,8 @@ EXECUTABLES := \ uninitialized_free \ uninitialized_realloc \ uninitialized_malloc_usable_size \ + eight_byte_overflow_small \ + eight_byte_overflow_large \ all: $(EXECUTABLES) diff --git a/test/simple-memory-corruption/eight_byte_overflow_large.c b/test/simple-memory-corruption/eight_byte_overflow_large.c new file mode 100644 index 0000000..f7253d6 --- /dev/null +++ b/test/simple-memory-corruption/eight_byte_overflow_large.c @@ -0,0 +1,12 @@ +#include + +__attribute__((optimize(0))) +int main(void) { + char *p = malloc(128 * 1024); + if (!p) { + return 1; + } + *(p + 128 * 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 new file mode 100644 index 0000000..6270ac3 --- /dev/null +++ b/test/simple-memory-corruption/eight_byte_overflow_small.c @@ -0,0 +1,12 @@ +#include + +__attribute__((optimize(0))) +int main(void) { + char *p = malloc(8); + if (!p) { + return 1; + } + *(p + 8 + 7) = 0; + free(p); + return 0; +}