From 3f08189aae215692c284eb4bc9e0350bbe72f988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Thu, 24 Apr 2025 12:50:52 +0200 Subject: [PATCH] fix(parsing/redirect): sometimes do not take a redirection into account debug notes: ++++++++++++++++++++++++++++++++++++++++++++++++++++ failed: ambiguous redirect ++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++ test input: export target="outfile1 outfile2" echo hello > $target echo $? echo hi >> $target echo $? cat < $target echo $? ls echo $? ++++ Got output: hello 0 hi 0 echo $? ls echo $? ++++ But expected: minishell: $target: ambiguous redirect 1 minishell: $target: ambiguous redirect 1 minishell: $target: ambiguous redirect 1 0 Reproduced this with rr record --cahos, see /home/khais/.local/share/rr/minishell-48 $ export target="outfile1 outfile2" $ echo hi > $target hi Break in simple_cmd_execute, second command has no redirections when it should have some, presumably this comes from some uninitialized memory somewhere. --- Makefile | 1 - src/parser/redirect/redirect_from_words.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 285ec08..42ece00 100644 --- a/Makefile +++ b/Makefile @@ -197,7 +197,6 @@ inttestst: all ./test.sh ctests: $(LIBFT) all - +make -C tests ctestsa: CFLAGS += $(ASAN) ctestsa: ctests diff --git a/src/parser/redirect/redirect_from_words.c b/src/parser/redirect/redirect_from_words.c index 99c8907..c0a2197 100644 --- a/src/parser/redirect/redirect_from_words.c +++ b/src/parser/redirect/redirect_from_words.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 17:31:35 by khais #+# #+# */ -/* Updated: 2025/04/17 11:44:45 by khais ### ########.fr */ +/* Updated: 2025/04/24 13:23:44 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,12 +78,13 @@ t_redirect *redir_from_words(t_worddesc *operator, redir->redirectee.dest = here_doc(specifier, STDIN_FILENO, app); worddesc_destroy(specifier); if (redir->redirectee.dest < 0) + { + ft_errno(FT_EERRNO); return (worddesc_destroy(operator), redirect_destroy(redir), NULL); + } } else redir->redirectee.filename = specifier; worddesc_destroy(operator); - if (redir->redirectee.dest < 0) - return (redirect_destroy(redir), NULL); return (redir); }