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; +}