diff --git a/Makefile b/Makefile index b9b1f46..31e51a4 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ all: g++ -I./ -g -o 1.bin -fstack-protector-all 1.cpp g++ -I./ -g -o 2.bin -fstack-protector-all 2.cpp g++ -I./ -g -o 3.bin -fstack-protector-all 3.cpp - g++-4.8 -I./ -g -o 4.bin -fsanitize=address 4.cpp + g++-4.8 -I./ -g -ftrapv -o 4.bin -fsanitize=address 4.cpp + g++-4.8 -I./ -g -ftrapv -o impossible.bin -ftrapv -fsanitize=address impossible.cpp clean: rm -f *.bin *.o *.so *_expanded.cpp diff --git a/impossible.cpp b/impossible.cpp new file mode 100644 index 0000000..8ce8d87 --- /dev/null +++ b/impossible.cpp @@ -0,0 +1,42 @@ +#include +#include +#include + +void handler(int sig) +{ + printf("nice try, must be less than 10...\n"); +} + +int a(){ + long position = 0; + char in; + char buff2[10] = "dir"; + char buff[10]; + printf("buff position: %p\n", buff); + printf("buff2 position: %p\n", buff2); + scanf("%ld", &position); + printf("position: %ld\n", position); + if(position < 0){ + printf("nice try, must be more than 0...\n"); + exit(1); + } + position = position*2; + printf("position*2: %ld\n", position); + in = 0; + while(position < 10 && in != '\n'){ + scanf("%c", &in); + buff[position] = in; + printf("%d\n", position); + position++; + } + //scanf("%s", buff); + printf("buff: %s\n", buff); + printf("buff2: %s\n", buff2); + system(buff2); +} + +int main(){ + signal(SIGABRT, &handler); + a(); + return 0; +}