From 93fcc6a9780e45af260aedc0a2c96b7ca247260e Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 3 Oct 2018 17:15:38 -0400 Subject: [PATCH] add simple string overflow test --- test/simple-memory-corruption/Makefile | 1 + .../string_overflow.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/simple-memory-corruption/string_overflow.c diff --git a/test/simple-memory-corruption/Makefile b/test/simple-memory-corruption/Makefile index d3e35d7..98b0564 100644 --- a/test/simple-memory-corruption/Makefile +++ b/test/simple-memory-corruption/Makefile @@ -20,6 +20,7 @@ EXECUTABLES := \ uninitialized_malloc_usable_size \ eight_byte_overflow_small \ eight_byte_overflow_large \ + string_overflow all: $(EXECUTABLES) diff --git a/test/simple-memory-corruption/string_overflow.c b/test/simple-memory-corruption/string_overflow.c new file mode 100644 index 0000000..fe89fa5 --- /dev/null +++ b/test/simple-memory-corruption/string_overflow.c @@ -0,0 +1,19 @@ +#include +#include +#include + +#include + +__attribute__((optimize(0))) +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; +}