diff --git a/.gitignore b/.gitignore index cd588b9..24b17ef 100644 --- a/.gitignore +++ b/.gitignore @@ -40,5 +40,8 @@ result testcmd unit_tests -# Python (CI) -*.pyc +# Debug +.dbug + +# AFL +afl/generated diff --git a/Makefile b/Makefile index 261f5b1..d1f34b3 100644 --- a/Makefile +++ b/Makefile @@ -70,6 +70,7 @@ endef $(eval $(call mk-profile, release, SRC, , $(BIN_NAME))) $(eval $(call mk-profile, debug, SRC, -D U_DEBUG_MODE -g3, debug)) $(eval $(call mk-profile, test, SRC, --coverage, test)) +$(eval $(call mk-profile, afl, SRC, -D AFL_MODE, afl_runner)) all: $(NAME_release) @@ -85,6 +86,31 @@ cov: tests_run --exclude-unreachable-branches \ --exclude tests +.PHONY: afl +afl: CC := AFL_USE_ASAN=1 afl-gcc-fast +afl: $(NAME_afl) + +define newline + + +endef + +AFL_FLAGS := -i afl/inputs +AFL_FLAGS += -x afl/tokens +AFL_FLAGS += -o afl/generated + +PROCS ?= $(shell nproc) + +.PHONY: afl_run +afl_run: afl + @ mkdir -p afl/generated + screen -dmS main_instance \ + afl-fuzz $(AFL_FLAGS) -M fuzzer_1 -- ./afl_runner + $(foreach instance, $(shell seq 1 $(PROCS)),\ + screen -dmS afl_$(instance) \ + afl-fuzz $(AFL_FLAGS) -S fuzzer_$(instance) -- ./afl_runner$(newline)) + watch -n 0.25 -- afl-whatsup -s afl/generated + clean: @ $(RM) $(OBJ) @ $(LOG_TIME) "$(C_YELLOW) RM $(C_PURPLE) $(OBJ) $(C_RESET)" diff --git a/afl/inputs/commands b/afl/inputs/commands new file mode 100644 index 0000000..9236c0a --- /dev/null +++ b/afl/inputs/commands @@ -0,0 +1,4 @@ +hi +cd +ls +env diff --git a/afl/tokens/tokens b/afl/tokens/tokens new file mode 100644 index 0000000..7acec45 --- /dev/null +++ b/afl/tokens/tokens @@ -0,0 +1,7 @@ +... ~ / \t +abc def ghi +jkl mno pqr +stu vw xyz +!! ? - = != + & >> << < > +012 345 678 9 diff --git a/src/exec.c b/src/exec.c index 1d354f7..72ab14d 100644 --- a/src/exec.c +++ b/src/exec.c @@ -146,6 +146,9 @@ int launch_bin(char *full_bin_path, char **args, env_t *env, char *buff) pid_t pid = fork(); if (pid == 0) { +#if defined(AFL_MODE) + exit(0); +#else if (execve(full_bin_path, args, env->env) < 0) { status = command_error(full_bin_path, args, errno); free_env(env); @@ -153,6 +156,7 @@ int launch_bin(char *full_bin_path, char **args, env_t *env, char *buff) free(buff); exit(status); } +#endif } waitpid(pid, &status, 0); return status;