diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-12 16:50:46 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-12 16:50:46 +0100 |
commit | 7d0d45b09ad2beb677ed1a22d37db1e40786519e (patch) | |
tree | 401b33b030a94c1dabac695c0ec188c7d9de43d8 /src/s_init.c | |
parent | Removed bloatcode (diff) | |
download | 42-minishell-7d0d45b09ad2beb677ed1a22d37db1e40786519e.tar.gz 42-minishell-7d0d45b09ad2beb677ed1a22d37db1e40786519e.tar.bz2 42-minishell-7d0d45b09ad2beb677ed1a22d37db1e40786519e.tar.xz 42-minishell-7d0d45b09ad2beb677ed1a22d37db1e40786519e.tar.zst 42-minishell-7d0d45b09ad2beb677ed1a22d37db1e40786519e.zip |
Securing mallocs
Diffstat (limited to 'src/s_init.c')
-rw-r--r-- | src/s_init.c | 12 |
1 files changed, 9 insertions, 3 deletions
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 <libft.h> -#include <stdlib.h> -#include <unistd.h> #ifdef __linux__ # include <linux/limits.h> #else # include <limits.h> #endif +#include <stdlib.h> +#include <unistd.h> #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); |