I am trying to get to know how buffer overflow works, so I am working on various simple examples, involving C and functions gets() and puts(). The source code for one on these programs is the following:
#include<stdio.h>
GetInput()
{
char buffer[8];
gets(buffer);
puts(buffer);
}
main();
{
GetInput();
exit 0;
}
I am compiling this with the following line:
gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack demo.c -mpreferred-stack-boundary=2 -g -o demo
GCC version is 4.4.3, 32 bits system, and kernel 2.6.32
When calling GetInput(), the return address to main() should be pushed into de stack, then store the previous EBP record, and then it should allocate 8 bytes for the local var buffer, so to overwrite the RET address, I should input 12 bytes and the intended RET address.
But that is not the case, when I load it into GDB and dissasemble GetInput(), it says the following:
0x080483f4 <+0>: push %ebp
0x080483f5 <+1>: mov %esp,%ebp
0x080483f7 <+3>: sub $0xc,%esp <-------
0x080483fa <+6>: lea -0x8(%ebp),%eax
0x080483fd <+9>: mov %eax,(%esp)
0x08048400 <+12>: call 0x804830c <gets@plt>
0x08048405 <+17>: lea -0x8(%ebp),%eax
0x08048408 <+20>: mov %eax,(%esp)
0x0804840b <+23>: call 0x804832c <puts@plt>
0x08048410 <+28>: leave
0x08048411 <+29>: ret
I've marked the line where it reserves 12 bytes instead of 8.
Can anyone help me get this?