D
DevarajA
Hi, I can't uderstand something about the local variables allocation on
the stack. Maybe I'm OT, I know... Here's the function, compiled on a
i386 computer with linux
/******************/
void funz(char *txt)
{
char buf[12];
strcpy(buf,txt); /*done intentionally*/
}
/*********************/
$gcc bof.c --static
$gdb a.out
(gdb)disassemble funz
Dump of assembler code for function funz:
0x08048214 <funz+0>: push %ebp <<ok, saves frame pointer
0x08048215 <funz+1>: mov %esp,%ebp <<ok, updates frame pointer
0x08048217 <funz+3>: sub $0x28,%esp <<???
This instruction reserves 40 bytes of the stack for local variables,
while I only have 12 bytes. What are the remaining 28 bytes used for?
Maybe you can tell from the following asm code, because I can't
0x0804821a <funz+6>: mov 0x8(%ebp),%eax
0x0804821d <funz+9>: mov %eax,0x4(%esp)
second argument on the second position of the stack
0x08048221 <funz+13>: lea 0xffffffe8(%ebp),%eax
what does this do? and what's in the middle of the stack?
0x08048224 <funz+16>: mov %eax,(%esp)
0x08048227 <funz+19>: call 0x804de00 <strcpy>
moves that thing on top of the stack and calls strcpy
From this code it looks like if strcpy wanted its arguments on the top
of the stack (nothing strange), but they one of them is initially in the
middle of that oversize stack. I can't understend why. Wouldn't be
simplier to push on the stack a copy of 0x8(%ebp) and 0xfffffffc(%ebp)?
Thank you in advance.
0x0804822c <funz+24>: leave
0x0804822d <funz+25>: ret
the stack. Maybe I'm OT, I know... Here's the function, compiled on a
i386 computer with linux
/******************/
void funz(char *txt)
{
char buf[12];
strcpy(buf,txt); /*done intentionally*/
}
/*********************/
$gcc bof.c --static
$gdb a.out
(gdb)disassemble funz
Dump of assembler code for function funz:
0x08048214 <funz+0>: push %ebp <<ok, saves frame pointer
0x08048215 <funz+1>: mov %esp,%ebp <<ok, updates frame pointer
0x08048217 <funz+3>: sub $0x28,%esp <<???
This instruction reserves 40 bytes of the stack for local variables,
while I only have 12 bytes. What are the remaining 28 bytes used for?
Maybe you can tell from the following asm code, because I can't
0x0804821a <funz+6>: mov 0x8(%ebp),%eax
0x0804821d <funz+9>: mov %eax,0x4(%esp)
second argument on the second position of the stack
0x08048221 <funz+13>: lea 0xffffffe8(%ebp),%eax
what does this do? and what's in the middle of the stack?
0x08048224 <funz+16>: mov %eax,(%esp)
0x08048227 <funz+19>: call 0x804de00 <strcpy>
moves that thing on top of the stack and calls strcpy
From this code it looks like if strcpy wanted its arguments on the top
of the stack (nothing strange), but they one of them is initially in the
middle of that oversize stack. I can't understend why. Wouldn't be
simplier to push on the stack a copy of 0x8(%ebp) and 0xfffffffc(%ebp)?
Thank you in advance.
0x0804822c <funz+24>: leave
0x0804822d <funz+25>: ret