I’m currently learning how to write shellcode and get a GCC warning “assignment of incompatible pointer type”. Why?
Greetings,
LM
char shellcode[] =
"\x31\xc0"
"\xb0\x01"
"\x31\xdb"
"\xcd\x80";
int main() {
void (*func)() = shellcode;
func();
return 0;
}
I’ll write my suggestion as an answer and whore for some reputation 🙂
You need to explicitly cast the data pointer into a function pointer. With a typedef for the appropriate function pointer, you can do so without making the code too hard to read:
This compiles cleanly with clang 1.1, but GCC 4.4.3 will still give you a warning about the pointer conversion — although now it is a more precise warning:
Skipping the “-pedantic” flag will make it compile cleanly with GCC too, but who ever does that seriously?