This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
csce465pine64backup/hw2/stack.c
2018-02-13 23:34:03 -06:00

29 lines
589 B
C
Executable file

// Credit: given in our homework handout.
/* stack.c */
/* This program has a buffer overflow vulnerability. */
/* Our task is to exploit this vulnerability */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bof(char *str)
{
char buffer[12];
/* The following statement has a buffer overflow problem */
strcpy(buffer, str);
return 1;
}
int main(int argc, char **argv)
{
char str[517];
FILE *badfile;
badfile = fopen("badfile", "r");
fread(str, sizeof(char), 517, badfile);
bof(str);
printf("Returned Properly\n");
return 1;
}