Compare commits

...

2 Commits

Author SHA1 Message Date
942dd444cc Fix infinite loop when lexing an invalid newline sequence 2025-03-30 22:03:12 +02:00
55f6dff543 Add basic fuzzing with afl++ 2025-03-30 22:01:53 +02:00
3 changed files with 16 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

@ -310,6 +310,7 @@ error_t *lexer_next_newline(lexer_t *lex, lexer_token_t *token) {
lex->character_number = 0;
lex->line_number += 1;
} else {
lexer_shift_buffer(lex, 1);
token->id = TOKEN_ERROR;
lex->character_number += 1;
token->value = strdup((char[]){lex->buffer[0]});

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