custom mutator fix

This commit is contained in:
vanhauser-thc
2022-11-14 22:47:34 +01:00
parent 1cc2029179
commit e5c725c4e0
2 changed files with 92 additions and 84 deletions

View File

@ -76,6 +76,8 @@ fuzz_run_target(afl_state_t *afl, afl_forkserver_t *fsrv, u32 timeout) {
u32 __attribute__((hot)) u32 __attribute__((hot))
write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) { write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) {
u8 sent = 0;
if (unlikely(afl->custom_mutators_count)) { if (unlikely(afl->custom_mutators_count)) {
ssize_t new_size = len; ssize_t new_size = len;
@ -140,12 +142,15 @@ write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) {
if (el->afl_custom_fuzz_send) { if (el->afl_custom_fuzz_send) {
el->afl_custom_fuzz_send(el->data, *mem, new_size); el->afl_custom_fuzz_send(el->data, *mem, new_size);
sent = 1;
} }
}); });
} else { }
if (likely(!sent)) {
/* everything as planned. use the potentially new data. */ /* everything as planned. use the potentially new data. */
afl_fsrv_write_to_testcase(&afl->fsrv, *mem, new_size); afl_fsrv_write_to_testcase(&afl->fsrv, *mem, new_size);
@ -172,12 +177,15 @@ write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) {
if (el->afl_custom_fuzz_send) { if (el->afl_custom_fuzz_send) {
el->afl_custom_fuzz_send(el->data, *mem, len); el->afl_custom_fuzz_send(el->data, *mem, len);
sent = 1;
} }
}); });
} else { }
if (likely(!sent)) {
/* boring uncustom. */ /* boring uncustom. */
afl_fsrv_write_to_testcase(&afl->fsrv, *mem, len); afl_fsrv_write_to_testcase(&afl->fsrv, *mem, len);

View File

@ -3,7 +3,6 @@
. ./test-pre.sh . ./test-pre.sh
$ECHO "$BLUE[*] Testing: custom mutator" $ECHO "$BLUE[*] Testing: custom mutator"
test "1" = "`../afl-fuzz | grep -i 'without python' >/dev/null; echo $?`" && {
# normalize path # normalize path
CUSTOM_MUTATOR_PATH=$(cd $(pwd)/../custom_mutators/examples;pwd) CUSTOM_MUTATOR_PATH=$(cd $(pwd)/../custom_mutators/examples;pwd)
test -e test-custom-mutator.c -a -e ${CUSTOM_MUTATOR_PATH}/example.c -a -e ${CUSTOM_MUTATOR_PATH}/example.py && { test -e test-custom-mutator.c -a -e ${CUSTOM_MUTATOR_PATH}/example.c -a -e ${CUSTOM_MUTATOR_PATH}/example.py && {
@ -74,7 +73,16 @@ test "1" = "`../afl-fuzz | grep -i 'without python' >/dev/null; echo $?`" && {
# Clean # Clean
rm -rf out errors core.* rm -rf out errors core.*
} || {
ls .
ls ${CUSTOM_MUTATOR_PATH}
$ECHO "$RED[!] cannot compile the test program or the custom mutator"
CODE=1
}
}
test "1" = "`../afl-fuzz | grep -i 'without python' >/dev/null; echo $?`" && {
test -e test-custom-mutator && {
# Run afl-fuzz w/ the Python mutator # Run afl-fuzz w/ the Python mutator
$ECHO "$GREY[*] running afl-fuzz for the Python mutator, this will take approx 10 seconds" $ECHO "$GREY[*] running afl-fuzz for the Python mutator, this will take approx 10 seconds"
{ {
@ -106,20 +114,12 @@ test "1" = "`../afl-fuzz | grep -i 'without python' >/dev/null; echo $?`" && {
$ECHO "$RED[!] cannot compile the test program or the custom mutator" $ECHO "$RED[!] cannot compile the test program or the custom mutator"
CODE=1 CODE=1
} }
#test "$CODE" = 1 && { $ECHO "$YELLOW[!] custom mutator tests currently will not fail travis" ; CODE=0 ; }
make -C ../utils/custom_mutators clean > /dev/null 2>&1
rm -f test-custom-mutator
rm -f test-custom-mutators
} || {
$ECHO "$YELLOW[-] no custom mutators in $CUSTOM_MUTATOR_PATH, cannot test"
INCOMPLETE=1
}
unset CUSTOM_MUTATOR_PATH
} || { } || {
$ECHO "$YELLOW[-] no python support in afl-fuzz, cannot test" $ECHO "$YELLOW[-] no python support in afl-fuzz, cannot test"
INCOMPLETE=1 INCOMPLETE=1
} }
make -C ../utils/custom_mutators clean > /dev/null 2>&1
rm -f test-custom-mutator test-custom-mutators
. ./test-post.sh . ./test-post.sh