From b0cf064f819357feedc77d6d5eb0de49e122554a Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 16 Jun 2018 22:50:18 +0200 Subject: Added command injection example and secured examples --- examples-secure/buffer-overflow/buffer-overflow.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples-secure/buffer-overflow/buffer-overflow.c (limited to 'examples-secure/buffer-overflow/buffer-overflow.c') diff --git a/examples-secure/buffer-overflow/buffer-overflow.c b/examples-secure/buffer-overflow/buffer-overflow.c new file mode 100644 index 0000000..261a58e --- /dev/null +++ b/examples-secure/buffer-overflow/buffer-overflow.c @@ -0,0 +1,19 @@ +#include +#include + +int main(void) +{ + char buf[16]; + int ok = 0; + + printf("Type admin password: "); + fgets(buf, sizeof buf, stdin); + buf[strlen(buf)-1] = '\0'; + + if (strcmp(buf, "pass123")) printf("\nWrong password!\n"); + else ok = 1; + + if (ok) printf("\nLogged in as admin.\n"); + + return 0; +} -- cgit v1.2.3