mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
Compare commits
3 commits
58a27d712b
...
ff3dfe3b84
| Author | SHA1 | Date | |
|---|---|---|---|
| ff3dfe3b84 | |||
| 3a88cbbad4 | |||
| f0d7dcc752 |
6 changed files with 106 additions and 3 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -35,3 +35,7 @@ compile_commands.json
|
|||
.vscode
|
||||
report.txt
|
||||
zms_testeur
|
||||
fuzz
|
||||
fuzz_hand_tester
|
||||
*CORPUS
|
||||
crash-*
|
||||
|
|
|
|||
14
Makefile
14
Makefile
|
|
@ -1,9 +1,10 @@
|
|||
NAME = minishell
|
||||
DEBUG = -g -O0
|
||||
FUZZ = fuzz
|
||||
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 = \
|
||||
|
|
@ -118,6 +119,7 @@ srcs = \
|
|||
objs = $(srcs:.c=.o)
|
||||
export objs
|
||||
minishell_objs = $(addsuffix .o,src/$(NAME)) $(objs)
|
||||
fuzz_objs = $(addsuffix .o,src/$(FUZZ)) $(objs)
|
||||
all_objs = $(minishell_objs)
|
||||
deps = $(all_objs:.o=.d)
|
||||
|
||||
|
|
@ -131,6 +133,14 @@ all: $(NAME)
|
|||
$(NAME): $(minishell_objs) $(LIBFT)
|
||||
$(CC) $(CFLAGS) -o $@ $(minishell_objs) $(LINCLUDE) $(LDLIBS)
|
||||
|
||||
$(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)
|
||||
|
|
|
|||
BIN
fuzz_hand_tester
Executable file
BIN
fuzz_hand_tester
Executable file
Binary file not shown.
39
src/fuzz.c
Normal file
39
src/fuzz.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fuzz.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/30 16:01:18 by kcolin #+# #+# */
|
||||
/* Updated: 2025/04/30 17:13:17 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "minishell.h"
|
||||
#include "parser/cmd/cmd_destroy.h"
|
||||
#include "parser/cmd_parsing.h"
|
||||
#include "unistd.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
t_minishell app;
|
||||
bzero(&app, sizeof(t_minishell));
|
||||
int null = open("/dev/null", O_RDONLY, 0);
|
||||
|
||||
char *line = (char *)calloc(size + 1, sizeof(char));
|
||||
memcpy(line, data, size);
|
||||
|
||||
dup2(null, STDIN_FILENO);
|
||||
close(null);
|
||||
t_cmd *cmd = minishell_parse(&app, line);
|
||||
|
||||
cmd_destroy(cmd);
|
||||
free(line);
|
||||
|
||||
return (0); // Values other than 0 and -1 are reserved for future use.
|
||||
}
|
||||
48
src/fuzz_hand_tester.c
Normal file
48
src/fuzz_hand_tester.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fuzz_hand_tester.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/09 16:53:02 by kcolin #+# #+# */
|
||||
/* Updated: 2025/04/29 16:40:44 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/30 18:00:28 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,8 @@ void redirect_destroy(t_redirect *redirect)
|
|||
{
|
||||
next = redirect->next;
|
||||
free(redirect->here_doc_eof);
|
||||
if (redirect->type == FT_HEREDOC)
|
||||
unlink(redirect->redirectee.filename->word);
|
||||
worddesc_destroy(redirect->redirectee.filename);
|
||||
free(redirect->unexpanded_filename);
|
||||
free(redirect);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue