diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | tests/Makefile | 6 | ||||
-rw-r--r-- | tests/mem.c | 15 | ||||
-rw-r--r-- | tests/stack.c | 16 |
4 files changed, 39 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a23ca02 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tests/mem +tests/stack diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..8dff5a0 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,6 @@ +.PHONY: all clean + +CC = clang + +all : mem stack + diff --git a/tests/mem.c b/tests/mem.c new file mode 100644 index 0000000..36ad3a9 --- /dev/null +++ b/tests/mem.c @@ -0,0 +1,15 @@ +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> + +/* mem.c -- Exhaust your memory */ +int main(void){ + void *ptr = NULL; + unsigned long mb = 1; + for (;;mb++) { + fprintf(stderr, "%lu MB\n", mb); + if ((ptr = realloc(ptr, mb * 1000000)) == NULL) { + raise(SIGABRT); + } + } +} diff --git a/tests/stack.c b/tests/stack.c new file mode 100644 index 0000000..36885d9 --- /dev/null +++ b/tests/stack.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdlib.h> + +void rec(int *ip); + +/* stack.c -- Cause a stack overflow */ +int main(void) { + int i = 0; + rec(&i); +} +void rec(int *ip) { + char i[256]; + printf("%u\n", (*ip)++); + rec(ip); +} + |