The modern compiler GCC is so powerful that it can even prevent buffer overflow in compilation phase so that OS can not run code on stack space.
For example:
void function(char *str)
{
char buffer[16];
strncpy(buffer, str, 256);
}
void main()
{
char large_string[256];
int i;
for( i = 0; i < 256; i++)
large_string[i] = 'A';
function(large_string);
}
The only way I can get the magic 0x41414141 is to set GCC compile parameter such like:
gcc -fno-stack-protector -z execstack stackoverflow.c -o stackoverflow
(I tested it on ubuntu 10.04 x86 lucid 32bits box)
Is there any way I can bypass the GCC stack smashing protection ?
large_string
. Thestrcpy()
won't be limited to just 255 bytes.