mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
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:
parent
bf26afce2b
commit
aca85c3583
2 changed files with 13 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
8
test.sh
8
test.sh
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue