home *** CD-ROM | disk | FTP | other *** search
- /* crashme: Create a string of random bytes and then jump to it.
- crashme <nbytes> <srand> <ntrys> [nsub] */
-
- char *crashme_version = "1.2 25-JUN-1991";
-
- /*
- * COPYRIGHT (c) 1990, 1991 BY *
- * GEORGE J. CARRETTE, CONCORD, MASSACHUSETTS. *
- * ALL RIGHTS RESERVED *
-
- Permission to use, copy, modify, distribute and sell this software
- and its documentation for any purpose and without fee is hereby
- granted, provided that the above copyright notice appear in all copies
- and that both that copyright notice and this permission notice appear
- in supporting documentation, and that the name of the author
- not be used in advertising or publicity pertaining to distribution
- of the software without specific, written prior permission.
-
- THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- SOFTWARE.
-
- A signal handler is set up so that in most cases the machine exception
- generated by the illegal instructions, bad operands, etc in the procedure
- made up of random data are caught; and another round of randomness may
- be tried. Eventually a random instruction may corrupt the program or
- the machine state in such a way that the program must halt. This is
- a test of the robustness of the hardware/software for instruction
- fault handling.
-
- Comments may be addressed to the author at GJC@MITECH.COM
-
- Version Date Description
- ----------------------------------------------------------------------
- 1.0 early 1990 initial hack.
- 1.1 19-SEP-1990 added more signals and an alarm to abort looping.
- 1.2 25-JUN-1991 added [nsub] to vfork multiple subprocesses of self.
-
-
- CRASH REPORTS
-
- Date, Machine Crashme Reported
- Crashme Ver Make Model OS Version Arguments by:
- ------------------------------------------------------------------------------
- 10-JUL-90 1.0 SUN 4/110 4.1 1000 20 200 GJC
- 10-JUL-90 1.0 SUN 4/280 4.0.3 1000 20 200 GJC
- 31-JUL-90 1.0 DIGITAL DECstation 3100 100 10 10000 GAVRON@ARIZONA.EDU
- 31-JUL-90 1.0 IBM RT 100 10 10000 GAVRON@ARIZONA.EDU
- 3-AUG-90 1.0 Alliant FX/2800 SJA@SIRIUS.HUT.FI
- 27-JUN-91 1.2 SUN 4/110 4.1.1 10 1000 10 LPH@PARADIGM.COM
- 27-JUN-91 1.2 SUN 4/110 4.1.1 1000 20 200 10 LPH@PARADIGM.COM
-
-
- Notes: Crashme V1.0 {1000 20 200} used to down the SUN 4/110. V1.2 does *not*
- crash SUNOS 4.1.1 on the same arguments. Although using the extra argument
- for subprocesses it will crash, with the console reporting:
- "Bad Trap, Bad Kernel Read Fault, Bus error. Reboot"
-
- */
-
-
- #include <stdio.h>
- #include <signal.h>
- #include <setjmp.h>
-
- long nbytes,nseed,ntrys;
- unsigned char *the_data;
- char *note_buffer;
- char *notes;
-
- note()
- {strcat(note_buffer,"\n");
- fputs(note_buffer,stdout);}
-
- jmp_buf again_buff;
-
- void (*badboy)();
-
- void again_handler(sig, code, scp, addr)
- int sig, code;
- struct sigcontext *scp;
- char *addr;
- {char *ss;
- switch(sig)
- {case SIGILL: ss = " illegal instruction"; break;
- case SIGTRAP: ss = " trace trap"; break;
- case SIGFPE: ss = " arithmetic exception"; break;
- case SIGBUS: ss = " bus error"; break;
- case SIGSEGV: ss = " segmentation violation"; break;
- case SIGIOT: ss = " IOT instruction"; break;
- case SIGEMT: ss = " EMT instruction"; break;
- case SIGALRM: ss = " alarm clock"; break;
- default: ss = "";}
- sprintf(notes,"Got signal %d%s",sig,ss);
- note();
- longjmp(again_buff,3);}
-
- set_up_signals()
- {signal(SIGILL,again_handler);
- signal(SIGTRAP,again_handler);
- signal(SIGFPE,again_handler);
- signal(SIGBUS,again_handler);
- signal(SIGSEGV,again_handler);
- signal(SIGIOT,again_handler);
- signal(SIGEMT,again_handler);
- signal(SIGALRM,again_handler);}
-
- compute_badboy()
- {long j,n;
- n = (nbytes < 0) ? - nbytes : nbytes;
- for(j=0;j<n;++j) the_data[j] = (rand() >> 7) & 0xFF;
- if (nbytes < 0)
- {sprintf(notes,"Dump of %ld bytes of data",n);
- note();
- for(j=0;j<n;++j)
- {fprintf(stdout,"%3d",the_data[j]);
- if ((j % 20) == 19) putc('\n',stdout); else putc(' ',stdout);}
- putc('\n',stdout);}}
-
- try_one_crash()
- {compute_badboy();
- if (nbytes > 0)
- (*badboy)();
- else if (nbytes == 0)
- while(1);}
-
- char *subprocess_ind = "subprocess";
-
- main(argc,argv)
- int argc; char **argv;
- {long nsubs;
- note_buffer = (char *) malloc(512);
- notes = note_buffer;
- if ((argc == 6) &&
- (strcmp(argv[5],subprocess_ind) == 0))
- {sprintf(note_buffer,"Subprocess %s: ",argv[4]);
- notes = note_buffer + strlen(note_buffer);
- sprintf(notes,"starting");
- note();
- old_main(4,argv);}
- else if (argc == 4)
- old_main(4,argv);
- else if (argc == 5)
- {nsubs = atol(argv[4]);
- sprintf(notes,"Creating %d crashme subprocesses",nsubs);
- note();
- vfork_main(nsubs,argv[0],atol(argv[1]),atol(argv[2]),atol(argv[3]));}
- else
- {sprintf(notes,"crashme <nbytes> <srand> <ntrys> [nsub]");
- note();}}
-
- old_main(argc,argv)
- int argc;
- char **argv;
- {sprintf(notes,"Crashme: (c) Copyright 1990, 1991 George J. Carrette");
- note();
- sprintf(notes,"Version: %s",crashme_version);
- note();
- nbytes = atol(argv[1]);
- nseed = atol(argv[2]);
- ntrys = atol(argv[3]);
- sprintf(notes,"crashme %ld %ld %ld",nbytes,nseed,ntrys);
- note();
- the_data = (unsigned char *) malloc((nbytes < 0) ? -nbytes : nbytes);
- badboy = (void (*)()) the_data;
- sprintf(notes,"Badboy at %d. 0x%X",badboy,badboy);
- note();
- srand(nseed);
- badboy_loop();}
-
- badboy_loop()
- {int i;
- for(i=0;i<ntrys;++i)
- {sprintf(notes,"try %ld",i);
- note();
- if (setjmp(again_buff) == 3)
- {sprintf(notes,"Barfed");
- note();}
- else
- {set_up_signals();
- alarm(10);
- try_one_crash();
- sprintf(notes,"didn't barf!");
- note();}}}
-
- vfork_main(nsubs,cmd,nb,sr,nt)
- long nsubs,nb,sr,nt;
- char *cmd;
- {long j,status,pid;
- char arg1[20],arg2[20],arg3[20],arg4[20];
- for(j=0;j<nsubs;++j)
- {sprintf(arg1,"%d",nb);
- sprintf(arg2,"%d",sr+j);
- sprintf(arg3,"%d",nt);
- sprintf(arg4,"%d",j+1);
- status = vfork();
- if (status == 0)
- {status = execl(cmd,cmd,arg1,arg2,arg3,arg4,subprocess_ind,0);
- if (status == -1)
- {perror(cmd);
- exit(1);}}
- else if (status < 0)
- perror(cmd);
- else
- {sprintf(notes,"pid = %d",status);
- note();}}
- while((pid = wait(&status)) > 0)
- {sprintf(notes,"pid %d exited with status %d",pid,status);
- note();}}
-
-