Add basic fuzzing with afl++

This commit is contained in:
omicron 2025-03-30 22:01:53 +02:00
parent df948b18c6
commit 55f6dff543
2 changed files with 15 additions and 5 deletions

View File

@ -1,4 +1,4 @@
.PHONY: all clean clean-objects run sanitize validate
.PHONY: all clean clean-objects clean-reports run sanitize validate fuzz
CC=clang
LD=clang
@ -9,8 +9,8 @@ SOURCES = $(shell find src/ -type f -name '*.c')
OBJECTS = $(SOURCES:.c=.o)
DEPENDENCIES = $(SOURCES:.c=.d)
TARGET?=oas
OUTPUTS=oas oas-asan oas-msan
RUNARGUMENTS=-tokens test.asm
OUTPUTS=oas oas-asan oas-msan oas-afl
RUNARGUMENTS?=-tokens tests/input/valid.asm
all: $(TARGET)
@ -18,6 +18,12 @@ all: $(TARGET)
run: $(TARGET)
./$(TARGET) $(RUNARGUMENTS)
fuzz:
make CC="afl-clang-fast" LD="afl-clang-fast" TARGET="oas-afl" clean-objects all
make clean-objects
mkdir -p reports/afl
afl-fuzz -i tests/input -o reports/afl -m none -- ./oas-afl -tokens @@
sanitize:
make CFLAGS="$(CFLAGS) -fsanitize=address,undefined" LDFLAGS="-fsanitize=address,undefined" TARGET="oas-asan" clean-objects all
make CFLAGS="$(CFLAGS) -fsanitize=memory -fsanitize-memory-track-origins=2" LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2" TARGET="oas-msan" clean-objects all
@ -37,6 +43,8 @@ $(TARGET): $(OBJECTS)
clean-objects:
rm -f $(OBJECTS) $(DEPENDENCIES)
clean-reports:
rm -rf reports/
clean: clean-objects
rm -f $(TARGET) $(OUTPUTS)
rm -rf reports/

View File

@ -3,7 +3,9 @@
set -euo pipefail
# Start with static analysis
scan-build -o reports/ -plist-html --status-bugs make clean all
make clean all
mkdir -p reports/static-analysis
scan-build -o reports/static-analysis/ -plist-html --status-bugs make all
# Run the sanitizer builds and valgrind
make clean sanitize all