diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-12 16:54:24 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-12 16:54:24 +0100 |
commit | 05482f383050f4ec950212433ad8ba0336167d34 (patch) | |
tree | 237ccb1c44be68f0f2610f99f7868a72d8e1b50e | |
parent | Securing mallocs (diff) | |
download | 42-minishell-05482f383050f4ec950212433ad8ba0336167d34.tar.gz 42-minishell-05482f383050f4ec950212433ad8ba0336167d34.tar.bz2 42-minishell-05482f383050f4ec950212433ad8ba0336167d34.tar.xz 42-minishell-05482f383050f4ec950212433ad8ba0336167d34.tar.zst 42-minishell-05482f383050f4ec950212433ad8ba0336167d34.zip |
One more secured
-rw-r--r-- | src/s_init.c | 4 | ||||
-rw-r--r-- | 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], |