From aca85c3583494361cb10cafbef2b4476aee05180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 22 Apr 2025 11:50:57 +0200 Subject: [PATCH] fix(expansion/redirection): prevent infinite loop of redir list pointing to itself also add a hard limit of OVER 9000! iterations for the problematic loop --- src/parser/redirect/redirect.c | 7 +++++-- test.sh | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/parser/redirect/redirect.c b/src/parser/redirect/redirect.c index e81d7d7..65c42f8 100644 --- a/src/parser/redirect/redirect.c +++ b/src/parser/redirect/redirect.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 17:27:53 by khais #+# #+# */ -/* Updated: 2025/04/18 12:55:08 by khais ### ########.fr */ +/* Updated: 2025/04/22 12:10:31 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back) { t_redirect *tmp; + size_t i; if (!(*init)) { @@ -22,7 +23,8 @@ t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back) return (*init); } tmp = *init; - while (tmp->next) + i = 0; + while (tmp->next && i++ < 9001) tmp = tmp->next; tmp->next = back; return (*init); @@ -44,5 +46,6 @@ t_redirect *redirect_pop(t_redirect **lst) return (NULL); first = *lst; (*lst) = first->next; + first->next = NULL; return (first); } diff --git a/test.sh b/test.sh index 4b457e9..8395d97 100755 --- a/test.sh +++ b/test.sh @@ -920,4 +920,12 @@ parsed command ╰─ here_doc_eof = [(null)] EOF +when_run < outfile > outfile +cat outfile +EOF +expecting <