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
This commit is contained in:
Khaïs COLIN 2025-04-22 11:50:57 +02:00
parent bf26afce2b
commit aca85c3583
2 changed files with 13 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -920,4 +920,12 @@ parsed command
╰─ here_doc_eof = [(null)]
EOF
when_run <<EOF "correctly handle multiple redirections"
echo hello > outfile > outfile
cat outfile
EOF
expecting <<EOF
hello
EOF
finalize