I have the following code that I'm using to test buffer overflow:
#include <stdio.h>
#include <string.h>
int PasswordOkay() {
char GoodPassword = 'F';
printf("The memory address of GoodPassword is: %p\n", (void*) &GoodPassword);
char Password[8];
printf("The memory address of password is: %p\n", (void*) &Password);
gets(Password);
if(!strcmp(Password, "SPOCKSUX"))
GoodPassword = 'T';
return (GoodPassword == 'T');
}
int main() {
puts("Enter Password:");
if(PasswordOkay())
puts("Hello, Dr. Bones");
else
puts("Access denied.");
}
On 32-bit the overflow works fine and 9T's as the password lets me succesfully log in.
On 64-bit I had these memory addresses:
The memory address of GoodPassword is: 0x7fff1b452a8f
The memory address of password is: 0x7fff1b452a80
So to try the overflow there, I did 16T's as the password. The login message appeared succesfull again, but it also gave a segmentation fault.(Which it did not with 32-bit).
My question is: Why does it give a segmentation fault on 64-bit? It shouldn't should it? Since I'm only overwriting GoodPassword.
Additional note: File was compiled with gcc, tried with optimizer on and off.