From 7313047fd119156888aa02a996027e884231d763 Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Sun, 14 Dec 2025 12:34:53 +0000 Subject: [PATCH] Simple fuzzer --- hosts/fuzz/Makefile | 9 +++++++++ hosts/fuzz/fuzz.c | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 hosts/fuzz/Makefile create mode 100644 hosts/fuzz/fuzz.c diff --git a/hosts/fuzz/Makefile b/hosts/fuzz/Makefile new file mode 100644 index 0000000..92e0b93 --- /dev/null +++ b/hosts/fuzz/Makefile @@ -0,0 +1,9 @@ +TOPDIR=../.. +all: + afl-clang-fast -g3 -fsanitize=address,undefined -Wall -DUVM32_MEMORY_SIZE=8388608 -I${TOPDIR}/uvm32 -I${TOPDIR}/common -o host-fuzz ${TOPDIR}/uvm32/uvm32.c fuzz.c + afl-fuzz -i${TOPDIR}/precompiled -oo ./host-fuzz + +clean: + rm -rf host-fuzz o host-fuzz.dSYM + + diff --git a/hosts/fuzz/fuzz.c b/hosts/fuzz/fuzz.c new file mode 100644 index 0000000..9d2cb94 --- /dev/null +++ b/hosts/fuzz/fuzz.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include "uvm32.h" +#include "../common/uvm32_common_custom.h" + +__AFL_FUZZ_INIT(); + +int main(int argc, char *argv[]) { + __AFL_INIT(); + uvm32_state_t vmst; + uvm32_evt_t evt; + + uvm32_init(&vmst); + unsigned char *rom = __AFL_FUZZ_TESTCASE_BUF; + while (__AFL_LOOP(10000)) { + uvm32_load(&vmst, rom, __AFL_FUZZ_TESTCASE_LEN); + uvm32_run(&vmst, &evt, 1000); + } + + return 0; +}