I'm reading Hacking: The Art of Exploitation (2nd Edition), and I'm currently on the section about buffer overflows.
In the first example, the variables are declared/initialized in this order:
int auth_flag = 0;
char password_buffer[16];
The example goes on to explain that you can use gdb to examine auth_flag
and password_buffer
's addresses, and you'll notice that auth_flag
's address is higher than password_buffer
's. Things to keep in mind: I'm running all of this in Ubuntu within Virtualbox on a Macbook Pro (Intel processor, 64-bit).
I compiled the first example's code like this: gcc -g -fno-stack-protector -o auth_overflow auth_overflow.c
As expected, auth_flag
's address is higher than password_buffer
's.
To remedy the problem presented above, the author explains you should switch the ordering of the declarations:
char password_buffer[16];
int auth_flag = 0;
I compiled the code the same way: gcc -g -fno-stack-protector -o auth_overflow2 auth_overflow2.c
Unfortunately, I did not see auth_flag
's address being lower than password_buffer
's. In fact, it was still higher. Why is this? What am I doing wrong?