From 05482f383050f4ec950212433ad8ba0336167d34 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Dec 2020 16:54:24 +0100 Subject: One more secured --- src/s_init.c | 4 ++++ src/u_vars_next.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/s_init.c b/src/s_init.c index a13f9f1..7e1c4e5 100644 --- a/src/s_init.c +++ b/src/s_init.c @@ -128,7 +128,11 @@ t_msh *s_init_msh(int argc, char *const argv[], char *const envp[]) } msh->env_fork_tmp[0][0] = '\0'; if (s_inc_shlvl(msh) == 1) + { + ft_memdel((void*)&msh->cwd); + ft_memdel((void*)&msh); return (NULL); + } s_init_sqb_ref_one(msh); s_init_sqb_ref_two(msh); s_init_sqb_ref_thr(msh); diff --git a/src/u_vars_next.c b/src/u_vars_next.c index 5ffdbb1..28cdd45 100644 --- a/src/u_vars_next.c +++ b/src/u_vars_next.c @@ -84,6 +84,7 @@ char u_subst_var_value(const char varname[], const char newval[], t_msh *msh) { + size_t i; long env_line; char new_line_fmt[ARG_MAX]; @@ -91,10 +92,14 @@ char u_subst_var_value(const char varname[], { ft_memdel((void*)&msh->envp[env_line]); ft_sprintf(new_line_fmt, "%s=%s", varname + 1, newval); - /* if ((msh->envp[env_line] = (char*)malloc((ft_strlen(new_line_fmt) + 1) * */ - /* sizeof(char))) == NULL) */ - if ((msh->envp[env_line] = NULL) == NULL) + if ((msh->envp[env_line] = (char*)malloc((ft_strlen(new_line_fmt) + 1) * + sizeof(char))) == NULL) { + i = env_line; + while (msh->envp[++i] != NULL) + ft_memdel((void*)&msh->envp[i]); + ft_delwords(msh->envp); + msh->envp = NULL; return (1); } (void)ft_strlcpy(msh->envp[env_line], -- cgit v1.2.3