#include /* Password checking function. This one always returns false, the general idea is to somehow bypass this... */ //unsigned long get_sp(void) { // __asm__("movl %esp,%eax"); //} int checkpw(char *name,char *password) { char s[100]; /* where we make a copy of the password */ // printf("stack is at %x\n",get_sp()); strcpy(s,password); /* blind copy */ /* Here is some real passwod checking code that for our purposes always returns false (0). */ return(0); } /* authenticate returns a 1 if the user,password are OK, otherwise it returns 0 The only valid username is "rotor" */ int authenticate(char *user, char *password) { if (strcmp(user,"rotor")==0) { return( checkpw(user,password) ); } else { return(0); } } /* This procedure adds some money to an account */ void credit_account(char *name, int amount) { printf("Crediting account for %s with %d\n",name,amount); /* The real system has database update code here that would execute right after the printf */ } /* main program for stack bomb assignment */ int main() { char name[1000]; /* buffer used to read in a name from stdin */ char password[1000]; /* buffer used to hold password */ /* You may replace the code here that reads the name and password from standard input (this is the only code you can replace). */ fgets(name,1000,stdin); /* read one line from standard input */ name[strlen(name)-1]=0; /* strip newline */ fgets(password,1000,stdin); /* read the second line */ password[strlen(password)-1]=0; /* strip newline */ /* ------------------------------------------------------------- You can't change any code below this line ! */ if (authenticate(name,password)) { credit_account(name,100); } else { printf("Boom! (sorry)\n"); } }