From 93da69aa9650b1a1c495dc060daab3efdd937331 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 16 Nov 2022 19:34:25 +0100 Subject: [PATCH] :art: Get afl back --- Makefile | 8 ++++---- src/main.c | 11 +++++++---- src/vm/vm.c | 5 +++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index accc51a4..a7262be0 100644 --- a/Makefile +++ b/Makefile @@ -69,9 +69,9 @@ CFLAGS += -Wno-pedantic CFLAGS += -DGWION_BUILTIN -all: options-show ${PRG} +all: options-show prg -${PRG}: ${GWLIBS} src/main.o +prg: ${GWLIBS} src/main.o @$(info link ${PRG}) @${CC} src/main.o -o ${PRG} ${LDFLAGS} ${LIBS} @@ -109,9 +109,9 @@ ast: ast/libgwion_ast.a afl: gwion-fuzz gwion-fuzz: - @touch src/parse/{scan*.c,check.c} src/emit/emit.c src/main.c + @touch src/parse/{scan*.c,check.c} src/emit/emit.c src/main.c src/vm/vm.c @+PRG=gwion-fuzz CC=afl-clang-fast CFLAGS=-D__FUZZING__ ${MAKE} - @touch src/parse/{scan*.c,check.c} src/emit/emit.c src/main.c + @touch src/parse/{scan*.c,check.c} src/emit/emit.c src/main.c src/vm/vm.c clean_core: @rm -f core.* *vgcore.* diff --git a/src/main.c b/src/main.c index 0a78f51e..d8abd6ef 100644 --- a/src/main.c +++ b/src/main.c @@ -20,13 +20,16 @@ static void sig(int unused NUSED) { #include "compile.h" static void afl_run(const Gwion gwion) { + const Env env = gwion->env; __AFL_INIT(); -// while (__AFL_LOOP(128)) { - while (__AFL_LOOP(32)) { - push_global(gwion, "[afl]"); + while (__AFL_LOOP(128)) { + const Nspc nspc = env->global_nspc; + env->curr = env->global_nspc = new_nspc(gwion->mp, "[afl]"); + env->global_nspc->parent = nspc; FILE *f = fdopen(0, "r"); if (compile_file(gwion, "afl", f)) gwion_run(gwion); - pop_global(gwion); + free_nspc(env->global_nspc, env->gwion); + env->curr = env->global_nspc = nspc; } } diff --git a/src/vm/vm.c b/src/vm/vm.c index 9386740e..c00a8efc 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -606,7 +606,12 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto] reg += SZ_INT; DISPATCH() regpushmaybe: + +#ifndef __AFL_HAVE_MANUAL_CONTROL *(m_uint *)reg = gw_rand((uint32_t *)vm->rand) > (UINT32_MAX / 2); +#else + *(m_uint *)reg = 0; +#endif reg += SZ_INT; DISPATCH(); funcreturn : { -- 2.43.0