adding buffer overflow example

This commit is contained in:
Omar Santos 2018-02-15 18:27:16 -05:00
parent 0ae3754d31
commit 7f9b4eb866
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,31 @@
# Buffer Overflow Example
***DO NOT USE THIS CODE METHODOLOGY***
This is an example of a very bad coding practice that introduces a buffer overflow.
```
#include <stdio.h>
void secretFunction()
{
printf("Omar's Crappy Function\n");
printf("This is a super secret function!\n");
}
void echo()
{
char buffer[20];
printf("Please enter your name:\n");
scanf("%s", buffer);
printf("You entered: %s\n", buffer);
}
int main()
{
echo();
return 0;
}
```
The `char buffer[20];` is a really bad idea. The rest will be demonstrated in the course.

View File

@ -0,0 +1,23 @@
#include <stdio.h>
void secretFunction()
{
printf("Omar's Crappy Function\n");
printf("This is a super secret function!\n");
}
void echo()
{
char buffer[20];
printf("Please enter your name below:\n");
scanf("%s", buffer);
printf("You entered: %s\n", buffer);
}
int main()
{
echo();
return 0;
}