Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Undesired values being pushed to the call stack

Hi everyone,

Suppose I've written the following chunk of code (I know it has a format string bug in it, so DON'T remark this):
[code]#include
int main(int argc, char *argv[])
{
int x = 1;
printf(argv[1]);
return 0;
}[/code]

As far as I know when the printf() function is being called the stack looks like this:
[code]old %ebp {2}
return address (printf)
argv[1]
x (1)
old %ebp {1}
return address (main)
argc
*argv[][/code]

This layout basically means that if I run the program with "%x" as its invocation argument (and yes, I know it's a format string bug) I should get the value of x, which is 1.

However, in reality what I get is this:
[code]$ ./program "%x" 8049658[/code]

Second execution attempt:
[code]$ ./format "%x %x %x %x" 8049658 ffffd4f8 8048469 1[/code]

My question is what are those strange values being pushed onto the stack? Is there any way to turn down this nasty feature?

Thanks in advance.
Sign In or Register to comment.