Trying (not) to crash with libpthread (6.3-RELEASE)

Mike deathjestr at gmail.com
Fri May 16 17:23:50 UTC 2008


> void
> sigcatcher(int sig) {
>  printf("[%p] signal %d\n", pthread_self(), sig);
>  printf("Test (probably) succeeded\n");
>  fflush(NULL);
>  success=1;
>  exit(0);
> }

Take a look at the man page for sigaction(2). Here's an excerpt:

"All functions not in the above lists are considered to be unsafe with
respect to signals.  That is to say, the behaviour of such functions when
called from a signal handler is undefined.  In general though, signal
handlers should do little more than set a flag; most other actions are
not safe."

> void *
> crashingthread(void *nada) {
>  /* This will likely crash */
>  char *x=malloc(1);
>
>  if(signal(SIGSEGV, sigcatcher)==SIG_ERR)
>   err(1, "signal(SIGSEGV, catchz0r)");
>
>  x[666]=0;
>
>  /* HOPEFULLY NOT REACHED (aargh! die harder!) */
>
>  int i;
>  for(i=1; 999999>i; i++)
>   x[i]=0;
>
>  /* NOT REACHED (either killed, or exit()'ed in sigcatcher) */
>  abort();
> }

Something like *(int*)0 = 0 is probably an easier, more reliable way to
crash your program. Maybe not quite as much fun though. ;-)


More information about the freebsd-hackers mailing list