From 7d0d45b09ad2beb677ed1a22d37db1e40786519e Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Dec 2020 16:50:46 +0100 Subject: Securing mallocs --- src/s_init.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/s_init.c') diff --git a/src/s_init.c b/src/s_init.c index a572c32..a13f9f1 100644 --- a/src/s_init.c +++ b/src/s_init.c @@ -11,13 +11,13 @@ /* ************************************************************************** */ #include -#include -#include #ifdef __linux__ # include #else # include #endif +#include +#include #include "b_export_next.h" #include "d_define.h" @@ -108,8 +108,12 @@ t_msh *s_init_msh(int argc, char *const argv[], char *const envp[]) if ((msh = (t_msh*)malloc(sizeof(t_msh))) == NULL) return (NULL); msh->envp = NULL; + (void)envp; if ((msh->envp = s_dupenv(envp)) == NULL) + { + ft_memdel((void*)&msh); return (NULL); + } msh->argc = argc - 1; msh->argv = (char**)argv; msh->ret = 0; @@ -118,11 +122,13 @@ t_msh *s_init_msh(int argc, char *const argv[], char *const envp[]) s_set_cwd(cwd, msh); if ((msh->cwd = ft_strdup(cwd)) == NULL) { + ft_delwords(msh->envp); ft_memdel((void*)&msh); return (NULL); } msh->env_fork_tmp[0][0] = '\0'; - s_inc_shlvl(msh); + if (s_inc_shlvl(msh) == 1) + return (NULL); s_init_sqb_ref_one(msh); s_init_sqb_ref_two(msh); s_init_sqb_ref_thr(msh); -- cgit v1.2.3