diff options
author | van Hauser <vh@thc.org> | 2020-07-21 13:15:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-21 13:15:59 +0200 |
commit | b6e65f98827470745d7df5cf1e38b506b9e839b0 (patch) | |
tree | 602abd8c1a1929aebda3f80665ffe02b435fdd00 /examples/defork/forking_target.c | |
parent | fc5cfc6cb309b072a45b991be117c17396e46a89 (diff) | |
parent | c2b04bdf6c596f5d220f27caead20d09452ed42d (diff) | |
download | afl++-b6e65f98827470745d7df5cf1e38b506b9e839b0.tar.gz |
Merge pull request #461 from AFLplusplus/new_splicing
New splicing
Diffstat (limited to 'examples/defork/forking_target.c')
-rw-r--r-- | examples/defork/forking_target.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/defork/forking_target.c b/examples/defork/forking_target.c new file mode 100644 index 00000000..98f6365a --- /dev/null +++ b/examples/defork/forking_target.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdint.h> +#include <sys/types.h> + +/* This is an example target for defork.c - fuzz using +``` +mkdir in; echo a > ./in/a +AFL_PRELOAD=./defork64.so ../../afl-fuzz -i in -o out -- ./forking_target @@ +``` +*/ + +int main(int argc, char **argv) { + + if (argc < 2) { + + printf("Example tool to test defork.\nUsage ./forking_target <input>\n"); + return -1; + + } + + pid_t pid = fork(); + if (pid == 0) { + + printf("We're in the child.\n"); + FILE *f = fopen(argv[1], "r"); + char buf[4096]; + fread(buf, 1, 4096, f); + uint32_t offset = buf[100] + (buf[101] << 8); + char test_val = buf[offset]; + return test_val < 100; + + } else if (pid < 0) { + + perror("fork"); + return -1; + + } else { + + printf("We are in the parent - defork didn't work! :( (pid=%d)\n", + (int)pid); + + } + + return 0; + +} + |