/* dumb vulnerable program example, that uses function pointers */ #include #include #include #include #define ERROR -1 #define BUFSIZE 64 void goodfunc() { printf("I'm the real goodfunc(). I have been called.\n"); return; } int main(int argc, char **argv) { static char buf[BUFSIZE]; static void (*funcptr)(); if (argc <= 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(ERROR); } funcptr = &goodfunc; memset(buf, 0, BUFSIZE); printf("argv[1] = %p\n", argv[1]); printf("buf = %p\n\n", buf); printf("before: funcptr = %p\n", funcptr); strncpy(buf, argv[2], strlen(argv[2])); printf("after: funcptr = %p\n\n", funcptr); (*funcptr)(); return 0; }