From 93f2f7b2d1c1f6466e257b4bccfcfaeb712cce76 Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Mon, 22 Feb 2021 12:52:50 -0500 Subject: [PATCH] Create strcpy_example2.c --- buffer_overflow_example/strcpy_example2.c | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 buffer_overflow_example/strcpy_example2.c diff --git a/buffer_overflow_example/strcpy_example2.c b/buffer_overflow_example/strcpy_example2.c new file mode 100644 index 0000000..4a228d2 --- /dev/null +++ b/buffer_overflow_example/strcpy_example2.c @@ -0,0 +1,32 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + + // Reserve 5 byte of buffer plus the terminating NULL. + // should allocate 8 bytes = 2 double words, + // To overflow, need more than 8 bytes... + char buffer[5]; // If more than 8 characters input + // by user, there will be access + // violation, segmentation fault + + // a prompt how to execute the program... + if (argc < 2) + { + printf("strcpy() NOT executed....\n"); + printf("Syntax: %s \n", argv[0]); + exit(0); + } + + // copy the user input to mybuffer, without any + // bound checking a secure version is srtcpy_s() + strcpy(buffer, argv[1]); + printf("buffer content= %s\n", buffer); + + // you may want to try strcpy_s() + printf("strcpy() executed...\n"); + + return 0; +}