Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

Segmentation Fault when editing code of executable file

$
0
0

Working on a Cyber Security Project:

When editing the code of a .exe file in c, it's possible to edit the code of a different exe file but not the exe file itself. It results in a segmentation fault.

Is there anyway to get around this ?

Code that produces segmentation fault:

sandbox.c

#include <stdio.h>

int main(){
FILE *fp2 = fopen("sandbox", "r+");
char cbuffer [100000];
int exe_len = fread(cbuffer, 1, sizeof(cbuffer), fp2);

fwrite (cbuffer , sizeof(char), sizeof(cbuffer), fp2);

static char a[10000] = "hello goodbye";
printf("%s\n", a );

return 0;
}

Code that doesn't error, also sandbox.c:

#include <stdio.h>

int main(){
FILE *fp2 = fopen("readme", "r+");
char cbuffer [100000];
int exe_len = fread(cbuffer, 1, sizeof(cbuffer), fp2);

fwrite (cbuffer , sizeof(char), sizeof(cbuffer), fp2);

static char a[10000] = "hello goodbye";
printf("%s\n", a );

return 0;
}

Error: Segmentation fault (core dumped)


Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>