fix segfault if ls | |

This commit is contained in:
kinou-p 2022-04-15 06:59:38 +02:00
parent fff746af50
commit 8d6301e9e0
4 changed files with 29 additions and 5 deletions

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/03/06 12:50:24 by apommier #+# #+# # # Created: 2022/03/06 12:50:24 by apommier #+# #+# #
# Updated: 2022/04/12 23:31:57 by apommier ### ########.fr # # Updated: 2022/04/15 05:49:45 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -36,7 +36,6 @@ OBJS = ${SRCS:.c=.o}
CC = clang CC = clang
CFLAGS = -Wall -Wextra -g CFLAGS = -Wall -Wextra -g
LIB = -lreadline LIB = -lreadline
#CFLAGS = -Wall -Wextra -Werror
RM = rm -rf RM = rm -rf
LIBFT = ./libft LIBFT = ./libft

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */ /* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/15 00:13:24 by apommier ### ########.fr */ /* Updated: 2022/04/15 06:01:07 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -81,6 +81,8 @@ void print_prompt(char **path)
free_cmd(cmd); free_cmd(cmd);
cmd = 0; cmd = 0;
} }
else
ft_putstr_fd("Minishell: error while parsing command\n", 2);
} }
free(input); free(input);
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */ /* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/15 02:37:34 by apommier ### ########.fr */ /* Updated: 2022/04/15 06:29:09 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -99,6 +99,8 @@ void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
} }
else if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK)) else if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK))
cmd->err_var = 127; cmd->err_var = 127;
else
cmd->err_var = 126;
} }
void execute(t_cmd *cmd, char **env) void execute(t_cmd *cmd, char **env)

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */ /* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/14 12:32:26 by apommier ### ########.fr */ /* Updated: 2022/04/15 06:00:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -80,6 +80,25 @@ t_cmd *split_cmd(t_cmd *cmd, char **cmds)
return (cmd); return (cmd);
} }
int is_pipe_good(char *str)
{
int i;
char next;
i = 0;
while (str[i])
{
if (str[i] == '|')
{
next = next_space(str, i + 1);
if (!next || next == '|' || next == '<' || next == '>')
return (0);
}
i++;
}
return (1);
}
t_cmd *set_cmd(char *input, char **env) t_cmd *set_cmd(char *input, char **env)
{ {
t_cmd *cmd; t_cmd *cmd;
@ -87,6 +106,8 @@ t_cmd *set_cmd(char *input, char **env)
if (!is_quote_good(input)) if (!is_quote_good(input))
return (0); return (0);
if (!is_pipe_good(input))
return (0);
cmds = ft_split_with_quote(input, '|'); cmds = ft_split_with_quote(input, '|');
//print_double_fd(cmds, 1); //print_double_fd(cmds, 1);
if (!cmds) if (!cmds)