From 137aa1d976b2018c991042675ed84ad3c8b8743c Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Sat, 18 Mar 2017 19:20:00 +0100 Subject: [PATCH] protecting against malloc failure in parser --- 42sh/includes/minishell.h | 2 +- 42sh/libft/includes/libft.h | 2 +- 42sh/src/parser/aggregate_sym.c | 4 ++-- 42sh/src/parser/ft_parse.c | 6 +++--- 42sh/src/parser/heredoc_parser.c | 4 +++- 42sh/src/parser/push_stack.c | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index c478145d..7b012022 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/18 18:42:58 by ariard ### ########.fr */ +/* Updated: 2017/03/18 19:05:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/includes/libft.h b/42sh/libft/includes/libft.h index 986cda46..167be558 100644 --- a/42sh/libft/includes/libft.h +++ b/42sh/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/03/17 21:30:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 19:08:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index a5723e84..9dc025f4 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/18 17:28:43 by ariard ### ########.fr */ +/* Updated: 2017/03/18 19:18:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -375,7 +375,7 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) t_sym *head; int i; - if (!*stack || !*new_sym || !*state) + if (!*stack || !new_sym || !*new_sym || !*state) return (1); i = -1; head = (*stack)->content; diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 383e4b3a..49426b09 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ -/* Updated: 2017/03/18 17:08:53 by ariard ### ########.fr */ +/* Updated: 2017/03/18 19:18:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,10 +37,10 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) if (pop_heredoc(token)) return (0); - while (*token) + while (parser && token && *token) { produce_sym(&parser->stack, parser->new_sym, token); - if (eval_sym(&parser->stack, *parser->new_sym)) + if (parser->new_sym && eval_sym(&parser->stack, *parser->new_sym)) return ((parser->state = ERROR)); if (aggregate_sym(&parser->stack, parser->new_sym, &parser->state)) return (0); diff --git a/42sh/src/parser/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index 01c20bd0..af941529 100644 --- a/42sh/src/parser/heredoc_parser.c +++ b/42sh/src/parser/heredoc_parser.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ -/* Updated: 2017/03/18 19:00:17 by ariard ### ########.fr */ +/* Updated: 2017/03/18 19:15:41 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,8 @@ int pop_heredoc(t_list **lst) t_list **head; t_redir *redir; + if (!lst || !*lst) + return (0); token = (*lst)->content; if (token->type == HEREDOCDATA && data_singleton()->parser.heredoc_queue != NULL) diff --git a/42sh/src/parser/push_stack.c b/42sh/src/parser/push_stack.c index c5d37e12..3ab774c2 100644 --- a/42sh/src/parser/push_stack.c +++ b/42sh/src/parser/push_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:48:30 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:22:32 by ariard ### ########.fr */ +/* Updated: 2017/03/18 19:15:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */