From e405e721fad46e594b633147a6940cfdd602e4c2 Mon Sep 17 00:00:00 2001 From: Davide Quarta Date: Tue, 6 Feb 2024 18:19:52 +0100 Subject: reuse first_pass aux var in persistent loop for record replay mode, keep area ptr and loc logic intact in record replay mode, move replay record example to own dir in utils, update docs, move record compat layer to separate header file --- include/afl-record-compat.h | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 include/afl-record-compat.h (limited to 'include/afl-record-compat.h') diff --git a/include/afl-record-compat.h b/include/afl-record-compat.h new file mode 100644 index 00000000..2c79595d --- /dev/null +++ b/include/afl-record-compat.h @@ -0,0 +1,67 @@ +#ifndef _HAVE_AFL_COMPAT_H +#define _HAVE_AFL_COMPAT_H + +#include + +#define FUZZ_BUF_SIZE 1024000 + +// extern ssize_t read(int fildes, void *buf, size_t nbyte); + +// extern int __afl_persistent_loop(unsigned int max_cnt); +// extern unsigned char fuzz_buf[]; + +#ifndef __AFL_HAVE_MANUAL_CONTROL + #define __AFL_HAVE_MANUAL_CONTROL +#endif + +#define __AFL_FUZZ_TESTCASE_LEN (read(0, fuzz_buf, FUZZ_BUF_SIZE)) +#define __AFL_FUZZ_TESTCASE_BUF fuzz_buf +#define __AFL_FUZZ_INIT() void sync(void); +#define __AFL_INIT() sync() +#define __AFL_LOOP(x) __afl_persistent_loop(x) + +unsigned char fuzz_buf[FUZZ_BUF_SIZE]; + +int __afl_persistent_loop(unsigned int max_cnt) { + + static unsigned int cycle_cnt = 1; + static unsigned short int inited = 0; + char tcase[PATH_MAX]; + + if (is_replay_record) { + + if (!inited) { + + cycle_cnt = replay_record_cnt; + inited = 1; + + } + + snprintf(tcase, PATH_MAX, "%s/%s", + replay_record_dir ? replay_record_dir : "./", + record_list[replay_record_cnt - cycle_cnt]->d_name); + +#ifdef AFL_PERSISTENT_REPLAY_ARGPARSE + if (record_arg) { + + *record_arg = tcase; + + } else + +#endif // AFL_PERSISTENT_REPLAY_ARGPARSE + { + + int fd = open(tcase, O_RDONLY); + dup2(fd, 0); + close(fd); + + } + + } + + return --cycle_cnt; + +} + +#endif // _HAVE_AFL_COMPAT_H + -- cgit 1.4.1 From 2ed2ac80bc632f39fa95e1d51c4f14ecde48355a Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 11 Mar 2024 10:30:35 +0000 Subject: fix record compat loop to replay correct number of inputs, and at least one input --- include/afl-record-compat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/afl-record-compat.h') diff --git a/include/afl-record-compat.h b/include/afl-record-compat.h index 2c79595d..677d47b0 100644 --- a/include/afl-record-compat.h +++ b/include/afl-record-compat.h @@ -24,7 +24,7 @@ unsigned char fuzz_buf[FUZZ_BUF_SIZE]; int __afl_persistent_loop(unsigned int max_cnt) { - static unsigned int cycle_cnt = 1; + static unsigned int cycle_cnt = 2; static unsigned short int inited = 0; char tcase[PATH_MAX]; @@ -32,7 +32,7 @@ int __afl_persistent_loop(unsigned int max_cnt) { if (!inited) { - cycle_cnt = replay_record_cnt; + cycle_cnt = replay_record_cnt+1; inited = 1; } -- cgit 1.4.1 From 08f6d59f505436f4aec70ddd341d27f1d7bd7ccf Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 11 Mar 2024 12:01:06 +0000 Subject: correct fix --- include/afl-record-compat.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/afl-record-compat.h') diff --git a/include/afl-record-compat.h b/include/afl-record-compat.h index 677d47b0..3e5d60e3 100644 --- a/include/afl-record-compat.h +++ b/include/afl-record-compat.h @@ -24,15 +24,15 @@ unsigned char fuzz_buf[FUZZ_BUF_SIZE]; int __afl_persistent_loop(unsigned int max_cnt) { - static unsigned int cycle_cnt = 2; + static unsigned int cycle_cnt = 1; static unsigned short int inited = 0; char tcase[PATH_MAX]; - if (is_replay_record) { + if (is_replay_record && cycle_cnt) { if (!inited) { - cycle_cnt = replay_record_cnt+1; + cycle_cnt = replay_record_cnt; inited = 1; } @@ -59,7 +59,7 @@ int __afl_persistent_loop(unsigned int max_cnt) { } - return --cycle_cnt; + return cycle_cnt--; } -- cgit 1.4.1