adding buffer overflow examples

This commit is contained in:
Omar Santos 2021-03-18 14:10:55 -04:00
parent 81da9ec76d
commit 0f5a65b7a5
4 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,29 @@
/* stack.c */
/* This is the program that introduces the buffer overflow vulnerability. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bof(char *str)
{
char buffer[12];
/* Can you spot the buffer overflow here? ;-) */
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;
}