parsing: pass correct arguments to prevent use-after-free

This commit is contained in:
Khaïs COLIN 2025-04-15 14:10:03 +02:00
parent ba9751e089
commit 5716c4b3dc
13 changed files with 65 additions and 47 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
/* Updated: 2025/04/15 11:38:55 by khais ### ########.fr */
/* Updated: 2025/04/15 14:15:49 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,31 +28,33 @@ void parse_error(t_minishell *app, t_worddesc *token)
app->last_return_value = 2;
}
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist *tokens)
t_cmd *minishell_group_or_simple_parse(t_minishell *app, t_wordlist **tokens)
{
if (tokens->word->token_type == OPEN_PARENTH_TOKEN)
if ((*tokens)->word->token_type == OPEN_PARENTH_TOKEN)
{
worddesc_destroy(wordlist_pop(&tokens));
worddesc_destroy(wordlist_pop(tokens));
return (minishell_group_cmd_parse(app, tokens));
}
else
return (minishell_simple_cmd_parse(app, tokens));
}
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist **tokens,
t_connector *connec)
{
t_worddesc *token;
t_cmd *opt;
token = tokens->word;
if ((*tokens) == NULL)
return (NULL);
token = (*tokens)->word;
if (token->token_type == OR_TOKEN || token->token_type == AND_TOKEN)
{
if (token->token_type == OR_TOKEN)
*connec = FT_OR;
else
*connec = FT_AND;
token = wordlist_pop(&tokens);
token = wordlist_pop(tokens);
worddesc_destroy(token);
opt = minishell_pipeline_parse(app, tokens);
if (!opt)
@ -65,7 +67,7 @@ t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_wordlist *tokens,
/*
** Parse list of commands or pipeline.
*/
t_cmd *minishell_cmds_parse(t_minishell *app, t_wordlist *tokens)
t_cmd *minishell_cmds_parse(t_minishell *app, t_wordlist **tokens)
{
t_cmd *subtree;
t_cmd *opt;
@ -109,7 +111,7 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line)
tokens = minishell_wordsplit(command_line);
if (!tokens)
return (NULL);
root_cmd = minishell_cmds_parse(app, tokens);
root_cmd = minishell_cmds_parse(app, &tokens);
if (!root_cmd)
{
if (ft_errno_get() != FT_ESUCCESS && !app->last_return_value)