/*************************************************************************** * ISA 563 * Example target of 'attacker' * * Copyleft by Muhammad Abdulla * **************************************************************************/ /* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #include #include #define CRASH "crash" void crash() { fprintf(stderr, "crashing ...\n"); exit(-1); } #include /* * argtest.c -- demonstrates how to access argument line arguments */ int main (int argc, char *argv[] ) { int i; // print the number of arguments first printf("This program is called with %d argument%c\n", argc, argc == 1 ? '\0' : 's'); // print all the arguments that are accessable for ( i = 0; i < argc; i++ ) { printf("argument[%d]: ", i); printf(argv[i]); // this is NOT secure // printf("%s", argv[i]); // this is more secure printf("\n"); // crash if the second argument "special" if ( i == 2 && strncmp(argv[i], CRASH, strlen(CRASH)) == 0 ) { crash(); } } return 0; }