/* This program has a buffer overflow vulnerability. From Computer and Internet Security by Du */ #include #include #include int foo(char *str) { char buffer[100]; /* The following statement has a buffer overflow problem */ strcpy(buffer, str); return 1; } int main(int argc, char **argv) { char str[400]; FILE *badfile; badfile = fopen("badfile", "r"); fread(str, sizeof(char), 300, badfile); foo(str); printf("Returned Properly\n"); return 1; }