From 67751202645e0bc05c0467b82cc0414d5cd892d9 Mon Sep 17 00:00:00 2001 From: wescande Date: Fri, 3 Mar 2017 17:59:39 +0100 Subject: [PATCH 1/2] protection de segv au lancement du shell (redirection entrante & nom de fichier non valid) --- 42sh/src/main/main.c | 9 +++++++-- 42sh/src/main/shell_get_avdata.c | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a4ca3108..8ac2065d 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/02 21:40:50 by ariard ### ########.fr */ +/* Updated: 2017/03/03 17:49:18 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,6 +33,7 @@ int handle_instruction(int fd) if ((ret = readline(fd, get_lexer_stack(lexer) || parser.state == UNDEFINED, &str))) { + ft_putnbr(ret); ft_putstr("bonjour"); if (ret == -1) return (-1); @@ -108,7 +109,11 @@ int main(int ac, char **av) shell_init(ac, av); DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); - fd = get_input_fd(); + if ((fd = get_input_fd() < 0)) + { + ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME); + return (1); + } while (handle_instruction(fd) == 0) { // lexer_clean; diff --git a/42sh/src/main/shell_get_avdata.c b/42sh/src/main/shell_get_avdata.c index 6194cbf3..16a34d13 100644 --- a/42sh/src/main/shell_get_avdata.c +++ b/42sh/src/main/shell_get_avdata.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 17:14:52 by jhalford #+# #+# */ -/* Updated: 2017/01/19 20:56:05 by ariard ### ########.fr */ +/* Updated: 2017/03/03 17:33:33 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ char *shell_get_avdata() data = data_singleton(); av = data->argv; i = 1; - while (av[i][0] == '-') + while (av[i] && av[i][0] == '-') { if (ft_strcmp(av[i], "--") == 0) { From d146126135c19da7df2293bfaae34b5d90589aef Mon Sep 17 00:00:00 2001 From: wescande Date: Fri, 3 Mar 2017 18:01:25 +0100 Subject: [PATCH 2/2] rectif makefile --- 42sh/Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index ae67e26f..eb5de9c9 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,11 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -<<<<<<< HEAD -# Updated: 2017/03/03 14:36:32 by ariard ### ########.fr # -======= -# Updated: 2017/03/02 16:23:48 by jhalford ### ########.fr # ->>>>>>> pda_execution +# Updated: 2017/03/03 18:00:59 by wescande ### ########.fr # # # # **************************************************************************** #