I have a simple code example that I'm following from the Smashing the Stack article on buffer overflows. I can overwrite the return address, but when it actually returns it segfaults.
This version prints out everything its supposed to. The address it tries to return to is the address of the first block of the shell code.
char shellcode =
ret = (char *)&ret + 8;//11 in main
printf("return address is %x\n",*ret);//correctly prints return address
printf("shell code located at %x\n",&shellcode);
(*ret) = &shellcode;
printf("If I get here it means my problem is in returning, not in touching the pointer\n");
printf("Trying to return to address: %x\n",*ret);
Here's a simple version that does work for comparison but doesn't do any shell coding, it just skips a line
Can the compiler tell that I'm trying to point my memory to something in data segment rather than something on the stack? Is there a way to tell if its a problem with the assembly code in the array?
void function(int a,int b, int c)
ret = &buffer1; //-4 stack pointer
(*ret) += 7;