From 7f9b4eb86604d58388b1584c5925066baac7b947 Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Thu, 15 Feb 2018 18:27:16 -0500 Subject: [PATCH] adding buffer overflow example --- buffer_overflow_example/README.md | 31 ++++++++++++++++++++++++++++++ buffer_overflow_example/bad_code.c | 23 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 buffer_overflow_example/README.md create mode 100644 buffer_overflow_example/bad_code.c diff --git a/buffer_overflow_example/README.md b/buffer_overflow_example/README.md new file mode 100644 index 0000000..15b33c2 --- /dev/null +++ b/buffer_overflow_example/README.md @@ -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 + +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. diff --git a/buffer_overflow_example/bad_code.c b/buffer_overflow_example/bad_code.c new file mode 100644 index 0000000..5e5c86e --- /dev/null +++ b/buffer_overflow_example/bad_code.c @@ -0,0 +1,23 @@ +#include + +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; +}