From ca7e62a73fec9e8c2d3536bc220bacfdfa090f36 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Fri, 30 May 2014 23:58:40 +0200 Subject: [PATCH] extended buffer overflow example --- c_pointers/chapter_5.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/c_pointers/chapter_5.c b/c_pointers/chapter_5.c index b58a7b1..407588f 100644 --- a/c_pointers/chapter_5.c +++ b/c_pointers/chapter_5.c @@ -97,7 +97,7 @@ int main(void) { // better: char *command = malloc(11); if (command != NULL) { - printf("%s: ", "Enter a command"); + printf("%s: ", "Enter a command (max. 10 chars): "); scanf("%10s", command); printf("You entered: %s with length: %zu\n", command, strlen(command)); free(command); @@ -107,7 +107,10 @@ int main(void) { // executes without warnings or errors on osx :D char *mem = malloc(11); if (mem != NULL) { - memset(mem, 0x42, 64); + memset(mem, 0x42, 16); + for (size_t i = 0; i < 16; i++) { + printf("mem[%zu] Address: %p : %c\n", i, &mem[i], mem[i]); + } free(mem); }