1 #include <stdio.h> 2 #include <unistd.h> 3 #include <stdint.h> 4 #include <sys/types.h> 5 6 /* This is an example target for defork.c - fuzz using 7 ``` 8 mkdir in; echo a > ./in/a 9 AFL_PRELOAD=./defork64.so ../../afl-fuzz -i in -o out -- ./forking_target @@ 10 ``` 11 */ 12 main(int argc,char ** argv)13int main(int argc, char **argv) { 14 15 if (argc < 2) { 16 17 printf("Example tool to test defork.\nUsage ./forking_target <input>\n"); 18 return -1; 19 20 } 21 22 pid_t pid = fork(); 23 if (pid == 0) { 24 25 printf("We're in the child.\n"); 26 FILE *f = fopen(argv[1], "r"); 27 char buf[4096]; 28 fread(buf, 1, 4096, f); 29 fclose(f); 30 uint32_t offset = buf[100] + (buf[101] << 8); 31 char test_val = buf[offset]; 32 return test_val < 100; 33 34 } else if (pid < 0) { 35 36 perror("fork"); 37 return -1; 38 39 } else { 40 41 printf("We are in the parent - defork didn't work! :( (pid=%d)\n", 42 (int)pid); 43 44 } 45 46 return 0; 47 48 } 49 50