1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-13 16:08:45 +02:00

」 feat: Added some security to the parsing

This commit is contained in:
2024-07-03 19:13:43 +02:00
parent 9f25b17170
commit d24f097ae9
6 changed files with 21 additions and 79 deletions

View File

@ -1,33 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_redir.c :+: :+: :+: */
/* check_argv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 18:17:26 by adjoly #+# #+# */
/* Updated: 2024/06/30 13:49:21 by adjoly ### ########.fr */
/* Created: 2024/07/03 16:34:19 by adjoly #+# #+# */
/* Updated: 2024/07/03 19:07:23 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "tokenizer.h"
#include <stdbool.h>
#include "parsing.h"
#include "error_msg.h"
bool check_redir(t_list *redir)
bool check_argv(t_list *token)
{
t_list *tmp;
t_redirection *tmp_redir;
t_list *tmp;
tmp = redir;
tmp = token;
while (tmp)
{
tmp_redir = tmp->content;
if (tmp_redir->sign == HEREDOC && \
!((t_redirection *)(tmp->content))->file_name)
return (send_error_parsing(ERROR_NO_EOF));
if (!((t_redirection *)(tmp->content))->file_name)
return (send_error_parsing(ERROR_NO_REDIR));
if (!((t_token *)tmp->content)->argv)
return (send_error_parsing(ERROR_NO_CMD));
tmp = tmp->next;
}
return (false);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 12:52:22 by adjoly #+# #+# */
/* Updated: 2024/06/30 17:26:09 by adjoly ### ########.fr */
/* Updated: 2024/07/03 16:17:02 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,8 +34,7 @@ bool check_pipe(char *readline)
{
if (*tmp == '|' && is_inquote(readline, tmp - readline) == FALSE)
{
tmp++;
tmp += strlen_till_end_char(tmp, ' ');
tmp += strlen_till_end_char(tmp + 1, ' ') + 1;
if (!*tmp)
return (send_error_parsing("No command after pipe"));
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 18:09:49 by adjoly #+# #+# */
/* Updated: 2024/06/30 16:11:03 by adjoly ### ########.fr */
/* Updated: 2024/07/03 16:15:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,12 +21,6 @@ char *get_program_name(char *argv_one)
return (prog_name);
}
void send_error(char *msg, char **argv)
{
ft_putstr_fd(argv[0], STDERR_FILENO);
ft_putendl_fd(msg, STDERR_FILENO);
}
bool send_error_parsing(char *msg)
{
ft_putstr_fd(get_program_name(NULL), STDERR_FILENO);