i have been reading about a function that can overwrite its return address.
void foo(const char* input)
{
char buf[10];
//What? No extra arguments supplied to printf?
//It's a cheap trick to view the stack 8-)
//We'll see this trick again when we look at format strings.
printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n"); //%p ie expect pointers
//Pass the user input straight to secure code public enemy #1.
strcpy(buf, input);
printf("%s\n", buf);
printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
}
It was sugggested that this is how the stack would look like
Address of foo = 00401000
My stack looks like:
00000000
00000000
7FFDF000
0012FF80
0040108A <-- We want to overwrite the return address for foo.
00410EDE
Question:
-. Why did the author arbitrarily choose the second last value as the return address of foo()?
-. Are values added to the stack from the bottom or from the top?
- apart from the function return address, what are the other values i apparently see on the stack? ie why isn't it filled with zeros
Thanks.