int main(int argc, char **argv) { pthread_t thr; pthread_attr_t attr; fprintf(stderr,"crasher: " __TIME__ "!@\n"); fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); if(argc > 1) { if(!strcmp(argv[1],"nostack")) crashnostack(); if(!strcmp(argv[1],"ctest")) return ctest(); if(!strcmp(argv[1],"exit")) exit(1); if(!strcmp(argv[1],"abort")) maybeabort(); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_create(&thr, &attr, test_thread, 0); while(1) sleep(1); } else { crash1(); // *((int*) 0) = 42; } return 0; }
void do_if (void) { header *cond; int flag; if (!udfon) { output("If only allowed in functions!\n"); error=111; return; } another : cond=scan(); if (error) return; flag=ctest(cond); if (error) return; if (!flag) if (scan_else()) goto another; }
static int do_action(const char* arg) { fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); if (!strncmp(arg, "thread-", strlen("thread-"))) { return do_action_on_thread(arg + strlen("thread-")); } else if (!strcmp(arg,"smash-stack")) { return smash_stack(42); } else if (!strcmp(arg,"stack-overflow")) { overflow_stack(NULL); } else if (!strcmp(arg,"nostack")) { crashnostack(); } else if (!strcmp(arg,"ctest")) { return ctest(); } else if (!strcmp(arg,"exit")) { exit(1); } else if (!strcmp(arg,"crash")) { return crash(42); } else if (!strcmp(arg,"abort")) { maybeabort(); } else if (!strcmp(arg, "heap-usage")) { abuse_heap(); } fprintf(stderr, "%s OP\n", __progname); fprintf(stderr, "where OP is:\n"); fprintf(stderr, " smash-stack overwrite a stack-guard canary\n"); fprintf(stderr, " stack-overflow recurse until the stack overflows\n"); fprintf(stderr, " heap-corruption cause a libc abort by corrupting the heap\n"); fprintf(stderr, " heap-usage cause a libc abort by abusing a heap function\n"); fprintf(stderr, " nostack crash with a NULL stack pointer\n"); fprintf(stderr, " ctest (obsoleted by thread-crash?)\n"); fprintf(stderr, " exit call exit(1)\n"); fprintf(stderr, " crash cause a SIGSEGV\n"); fprintf(stderr, " abort call abort()\n"); fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); fprintf(stderr, "on the process' main thread.\n"); return EXIT_SUCCESS; }
static int do_action(const char* arg) { fprintf(stderr,"crasher: init pid=%d tid=%d\n", getpid(), gettid()); if (!strncmp(arg, "thread-", strlen("thread-"))) { return do_action_on_thread(arg + strlen("thread-")); } else if (!strcmp(arg, "SIGSEGV-non-null")) { sigsegv_non_null(); } else if (!strcmp(arg, "smash-stack")) { volatile int len = 128; return smash_stack(&len); } else if (!strcmp(arg, "stack-overflow")) { overflow_stack(NULL); } else if (!strcmp(arg, "nostack")) { crashnostack(); } else if (!strcmp(arg, "ctest")) { return ctest(); } else if (!strcmp(arg, "exit")) { exit(1); } else if (!strcmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { return crash(42); } else if (!strcmp(arg, "abort")) { maybe_abort(); } else if (!strcmp(arg, "assert")) { __assert("some_file.c", 123, "false"); } else if (!strcmp(arg, "assert2")) { __assert2("some_file.c", 123, "some_function", "false"); } else if (!strcmp(arg, "fortify")) { char buf[10]; __read_chk(-1, buf, 32, 10); while (true) pause(); } else if (!strcmp(arg, "LOG_ALWAYS_FATAL")) { LOG_ALWAYS_FATAL("hello %s", "world"); } else if (!strcmp(arg, "LOG_ALWAYS_FATAL_IF")) { LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); } else if (!strcmp(arg, "SIGFPE")) { raise(SIGFPE); return EXIT_SUCCESS; } else if (!strcmp(arg, "SIGTRAP")) { raise(SIGTRAP); return EXIT_SUCCESS; } else if (!strcmp(arg, "heap-usage")) { abuse_heap(); } else if (!strcmp(arg, "SIGSEGV-unmapped")) { char* map = reinterpret_cast<char*>(mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)); munmap(map, sizeof(int)); map[0] = '8'; } fprintf(stderr, "%s OP\n", __progname); fprintf(stderr, "where OP is:\n"); fprintf(stderr, " smash-stack overwrite a stack-guard canary\n"); fprintf(stderr, " stack-overflow recurse until the stack overflows\n"); fprintf(stderr, " heap-corruption cause a libc abort by corrupting the heap\n"); fprintf(stderr, " heap-usage cause a libc abort by abusing a heap function\n"); fprintf(stderr, " nostack crash with a NULL stack pointer\n"); fprintf(stderr, " ctest (obsoleted by thread-crash?)\n"); fprintf(stderr, " exit call exit(1)\n"); fprintf(stderr, " abort call abort()\n"); fprintf(stderr, " assert call assert() without a function\n"); fprintf(stderr, " assert2 call assert() with a function\n"); fprintf(stderr, " fortify fail a _FORTIFY_SOURCE check\n"); fprintf(stderr, " LOG_ALWAYS_FATAL call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " LOG_ALWAYS_FATAL_IF call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " SIGFPE cause a SIGFPE\n"); fprintf(stderr, " SIGSEGV cause a SIGSEGV at address 0x0 (synonym: crash)\n"); fprintf(stderr, " SIGSEGV-non-null cause a SIGSEGV at a non-zero address\n"); fprintf(stderr, " SIGSEGV-unmapped mmap/munmap a region of memory and then attempt to access it\n"); fprintf(stderr, " SIGTRAP cause a SIGTRAP\n"); fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); fprintf(stderr, "on the process' main thread.\n"); return EXIT_SUCCESS; }