From 3a88cbbad4e6facf35ddfae3571d29a4db51888f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Wed, 30 Apr 2025 17:30:16 +0200 Subject: [PATCH] fuzz: add hand tester --- .gitignore | 1 + Makefile | 6 +++++- src/fuzz_hand_tester.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/fuzz_hand_tester.c diff --git a/.gitignore b/.gitignore index 7d914b0..f75ec7f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,5 +36,6 @@ compile_commands.json report.txt zms_testeur fuzz +fuzz_hand_tester *CORPUS crash-* diff --git a/Makefile b/Makefile index 29e4b5d..d1562a5 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DEBUG = -g -O1 # -fno-omit-frame-pointer is to prevent malloc stacktraces from being truncated, # see "My malloc stacktraces are too short" here: # https://github.com/google/sanitizers/wiki/AddressSanitizer -ASAN = -fsanitize=address -fno-omit-frame-pointer +ASAN = -fsanitize=address,undefined -fno-omit-frame-pointer TSAN = -fsanitize=thread UBSAN = -fsanitize=undefined LDLIBS = \ @@ -137,6 +137,10 @@ $(FUZZ): CFLAGS += -fsanitize=fuzzer,address,undefined $(FUZZ): $(fuzz_objs) $(LIBFT) $(CC) $(CFLAGS) -o $@ $(fuzz_objs) $(LINCLUDE) $(LDLIBS) +#fuzz_hand_tester: CFLAGS += $(ASAN) +fuzz_hand_tester: $(objs) src/fuzz_hand_tester.o $(LIBFT) + $(CC) $(CFLAGS) -o $@ src/fuzz_hand_tester.o $(objs) $(LINCLUDE) $(LDLIBS) + $(LIBFT): CFLAGS+=-DBUFFER_SIZE=1 $(LIBFT): +$(MAKE) -C $(LIBFTDIR) diff --git a/src/fuzz_hand_tester.c b/src/fuzz_hand_tester.c new file mode 100644 index 0000000..30f403d --- /dev/null +++ b/src/fuzz_hand_tester.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fuzz_hand_tester.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/30 17:30:53 by kcolin #+# #+# */ +/* Updated: 2025/04/30 17:36:33 by kcolin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "fcntl.h" +#include "minishell.h" +#include "parser/cmd/cmd_destroy.h" +#include "parser/cmd_parsing.h" +#include "unistd.h" +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + t_minishell app; + bzero(&app, sizeof(t_minishell)); + int null = open("/dev/null", O_RDONLY, 0); + + if (argc != 2) + return (1); + FILE *in = fopen(argv[1], "rb"); + fseek(in, 0, SEEK_END); + long fsize = ftell(in); + fseek(in, 0, SEEK_SET); /* same as rewind(f); */ + char *line = malloc(fsize + 1); + fread(line, fsize, 1, in); + fclose(in); + line[fsize] = 0; + + + dup2(null, STDIN_FILENO); + close(null); + t_cmd *cmd = minishell_parse(&app, line); + + cmd_destroy(cmd); + free(line); + return (0); +}