From 55f6dff5434f8760998000f0e73d3f60f1e1698a Mon Sep 17 00:00:00 2001 From: omicron Date: Sun, 30 Mar 2025 22:01:53 +0200 Subject: [PATCH] Add basic fuzzing with afl++ --- Makefile | 16 ++++++++++++---- validate.sh | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 091f129..7906077 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/validate.sh b/validate.sh index 6169159..10c2142 100755 --- a/validate.sh +++ b/validate.sh @@ -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