redirection parsing: detect malformed redirection

This commit is contained in:
Khaïs COLIN 2025-03-10 16:40:02 +01:00
parent 06dd3c3e83
commit 5df876bba3
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 26 additions and 8 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 12:40:46 by khais #+# #+# */
/* Updated: 2025/02/21 15:38:54 by khais ### ########.fr */
/* Updated: 2025/03/10 16:56:52 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,6 +51,8 @@ char *ft_strerror(t_errno errno)
[FT_EINVAL] = "Invalid argument",
[FT_EBADID] = "Bad identifier",
[FT_EUNEXPECTED_PIPE] = "minishell: syntax error near unexpected token `|'",
[FT_EMALFORMED_REDIRECTION] = "minishell: malformed redirection (perhaps a \
missing filename)",
};
if (errno >= 0 && errno < FT_EMAXERRNO)

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 12:40:58 by khais #+# #+# */
/* Updated: 2025/02/21 15:37:56 by khais ### ########.fr */
/* Updated: 2025/03/10 16:38:28 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@ typedef enum e_errno
FT_EINVAL,
FT_EBADID,
FT_EUNEXPECTED_PIPE,
FT_EMALFORMED_REDIRECTION,
FT_EMAXERRNO,
} t_errno;

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/07 12:30:04 by khais #+# #+# */
/* Updated: 2025/03/10 16:11:46 by khais ### ########.fr */
/* Updated: 2025/03/10 16:40:17 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
#include "redirection_list.h"
#include <stdlib.h>
#include "redirection_type.h"
#include "../../ft_errno.h"
#include <unistd.h>
/*
@ -53,6 +54,8 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
{
wordlist_destroy_idx(&cmd->words, i);
marker = wordlist_pop_idx(&cmd->words, i);
if (marker == NULL)
return (ft_errno(FT_EMALFORMED_REDIRECTION), NULL);
redirection = redirection_create(type, marker);
if (redirection == NULL)
return (NULL);
@ -60,8 +63,7 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
if (cmd->redirections == NULL)
return (redirection_destroy(redirection), NULL);
}
else
i++;
i++;
}
return (cmd);
}