aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvanhauser-thc <vh@thc.org>2024-05-13 13:42:58 +0200
committervanhauser-thc <vh@thc.org>2024-05-13 13:42:58 +0200
commitb282ce999d2ab9428210deb0e838f45a6a534084 (patch)
treeebacb99b02814ec203c0719249c9f8bc9c5bb0b8
parent24b9d74e70107a4517396d7fa940140e206398bf (diff)
downloadafl++-b282ce999d2ab9428210deb0e838f45a6a534084.tar.gz
post_process after trim
-rw-r--r--docs/Changelog.md1
-rw-r--r--docs/custom_mutators.md5
-rw-r--r--src/afl-fuzz-run.c62
-rwxr-xr-xtest/test-llvm.sh5
4 files changed, 71 insertions, 2 deletions
diff --git a/docs/Changelog.md b/docs/Changelog.md
index 9a95e343..818010a7 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -7,6 +7,7 @@
* afl-fuzz
- added AFL_DISABLE_REDUNDANT for huge queues
- fix AFL_PERSISTENT_RECORD
+ - run custom_post_process after standard trimming
- prevent filenames in the queue that have spaces
- minor fix for FAST schedules
- more frequent stats update when syncing (todo: check performance impact)
diff --git a/docs/custom_mutators.md b/docs/custom_mutators.md
index 73e3c802..b7a7032f 100644
--- a/docs/custom_mutators.md
+++ b/docs/custom_mutators.md
@@ -266,6 +266,11 @@ trimmed input. Here's a quick API description:
Omitting any of three trimming methods will cause the trimming to be disabled
and trigger a fallback to the built-in default trimming routine.
+**IMPORTANT** If you have a custom post process mutator that needs to be run
+after trimming, you must call it yourself at the end of your successful
+trimming!
+
+
### Environment Variables
Optionally, the following environment variables are supported:
diff --git a/src/afl-fuzz-run.c b/src/afl-fuzz-run.c
index ed7cb4ce..2a55da00 100644
--- a/src/afl-fuzz-run.c
+++ b/src/afl-fuzz-run.c
@@ -1028,6 +1028,68 @@ u8 trim_case(afl_state_t *afl, struct queue_entry *q, u8 *in_buf) {
if (needs_write) {
+ // run afl_custom_post_process
+
+ if (unlikely(afl->custom_mutators_count) &&
+ likely(!afl->afl_env.afl_post_process_keep_original)) {
+
+ ssize_t new_size = q->len;
+ u8 *new_mem = in_buf;
+ u8 *new_buf = NULL;
+
+ LIST_FOREACH(&afl->custom_mutator_list, struct custom_mutator, {
+
+ if (el->afl_custom_post_process) {
+
+ new_size = el->afl_custom_post_process(el->data, new_mem, new_size,
+ &new_buf);
+
+ if (unlikely(!new_buf || new_size <= 0)) {
+
+ new_size = 0;
+ new_buf = new_mem;
+
+ } else {
+
+ new_mem = new_buf;
+
+ }
+
+ }
+
+ });
+
+ if (unlikely(!new_size)) {
+
+ new_size = q->len;
+ new_mem = in_buf;
+
+ }
+
+ if (unlikely(new_size < afl->min_length)) {
+
+ new_size = afl->min_length;
+
+ } else if (unlikely(new_size > afl->max_length)) {
+
+ new_size = afl->max_length;
+
+ }
+
+ q->len = new_size;
+
+ if (new_mem != in_buf && new_mem != NULL) {
+
+ new_buf = afl_realloc(AFL_BUF_PARAM(out_scratch), new_size);
+ if (unlikely(!new_buf)) { PFATAL("alloc"); }
+ memcpy(new_buf, new_mem, new_size);
+
+ in_buf = new_buf;
+
+ }
+
+ }
+
s32 fd;
if (unlikely(afl->no_unlink)) {
diff --git a/test/test-llvm.sh b/test/test-llvm.sh
index aef7a5e2..13e1bad1 100755
--- a/test/test-llvm.sh
+++ b/test/test-llvm.sh
@@ -197,7 +197,8 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
for I in char short int long "long long"; do
for BITS in 8 16 32 64; do
bin="$testcase-split-$I-$BITS.compcov"
- AFL_LLVM_INSTRUMENT=AFL AFL_DEBUG=1 AFL_LLVM_LAF_SPLIT_COMPARES_BITW=$BITS AFL_LLVM_LAF_SPLIT_COMPARES=1 ../afl-clang-fast -fsigned-char -DINT_TYPE="$I" -o "$bin" "$testcase" > test.out 2>&1;
+ #AFL_LLVM_INSTRUMENT=AFL
+ AFL_DEBUG=1 AFL_LLVM_LAF_SPLIT_COMPARES_BITW=$BITS AFL_LLVM_LAF_SPLIT_COMPARES=1 ../afl-clang-fast -fsigned-char -DINT_TYPE="$I" -o "$bin" "$testcase" > test.out 2>&1;
if ! test -e "$bin"; then
cat test.out
$ECHO "$RED[!] llvm_mode laf-intel/compcov integer splitting failed! ($testcase with type $I split to $BITS)!";
@@ -269,7 +270,7 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
{
mkdir -p in
echo 00000000000000000000000000000000 > in/in
- AFL_BENCH_UNTIL_CRASH=1 ../afl-fuzz -l 3 -m none -V30 -i in -o out -c ./test-cmplog -- ./test-c >>errors 2>&1
+ AFL_BENCH_UNTIL_CRASH=1 ../afl-fuzz -Z -l 3 -m none -V30 -i in -o out -c ./test-cmplog -- ./test-c >>errors 2>&1
} >>errors 2>&1
test -n "$( ls out/default/crashes/id:000000* out/default/hangs/id:000000* 2>/dev/null )" && {
$ECHO "$GREEN[+] afl-fuzz is working correctly with llvm_mode cmplog"