# IERG4130 — coverage-guided fuzzing target
# Uses AFL's instrumenting compiler if present, else gcc + ASan.
AFL := $(shell command -v afl-clang-fast 2>/dev/null)
ifeq ($(AFL),)
FUZZCC := gcc -fsanitize=address -g
else
FUZZCC := afl-clang-fast -fsanitize=address
endif

.PHONY: all repro fuzz clean
all: example

example: example.c
	$(FUZZCC) $< -o $@

# reproduce the crash by hand -> ASan: stack-buffer-overflow
repro: example
	printf 'abc\xff' | ./example ; true

# fuzz it (requires AFL installed)
fuzz: example
	mkdir -p output
	afl-fuzz -D -i input -o output -- ./example

clean:
	rm -f example
