I was looking at this example w.r.t executing code in the stack:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char shellcode[] = “\xeb\xfe”;
int main(int argc, char *argv[]){
void (*f)();
char x[4];
memcpy(x, shellcode, sizeof(shellcode));
f = (void (*)()) x;
f();
}
This causes a segmentation fault. My understanding this is because the shellcode runs out of memory for the rest of the bytes as x only has a size of 4 bytes. And this results in creating a write operation of copying to stack memory and that causes a seg. fault as stack memory is read only. Is my understanding correct ?
\xmeans the next two characters indicate the hexadecimal value of the byte which is actually put in the program. - ughoavgfhw