Skip to content

Commit

Permalink
corrected export leak
Browse files Browse the repository at this point in the history
  • Loading branch information
zakissimo committed Jan 12, 2023
1 parent a9c6743 commit a9c36eb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
34 changes: 32 additions & 2 deletions unset.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,41 @@
/* By: brenaudo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/02 11:31:23 by brenaudo #+# #+# */
/* Updated: 2023/01/09 13:21:10 by zhabri ### ########.fr */
/* Updated: 2023/01/12 13:10:50 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

static bool is_valid_identifier(char *identifier)
{
int i;
char *err;

i = 1;
if (!ft_isalpha(identifier[0]) && identifier[0] != '_')
{
err = ft_strjoin("minishell: unset: ", identifier);
err = ft_strjoinf(err, ": not a valid identifier\n");
ft_putstr_fd(err, 2);
free(err);
return (false);
}
while (identifier[i])
{
if (!ft_isalnum(identifier[i]) && identifier[i] != '_')
{
err = ft_strjoin("minishell: unset: ", identifier);
err = ft_strjoinf(err, ": not a valid identifier\n");
ft_putstr_fd(err, 2);
free(err);
return (false);
}
i++;
}
return (true);
}

void unset_parent_arg(char **cmd_split, int index)
{
char *name;
Expand Down Expand Up @@ -53,7 +82,8 @@ bool unset_parent(void)
{
i = 0;
while (cmd_split[++i])
unset_parent_arg(cmd_split, i);
if (is_valid_identifier(cmd_split[i]))
unset_parent_arg(cmd_split, i);
free_tab(cmd_split);
return (true);
}
Expand Down
11 changes: 8 additions & 3 deletions utils_export_bis.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: zhabri <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 10:38:28 by zhabri #+# #+# */
/* Updated: 2023/01/06 10:48:30 by zhabri ### ########.fr */
/* Updated: 2023/01/12 13:17:06 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -32,12 +32,17 @@ void free_and_set_exit_ret(char **var_split, int ret)

void init_new_var(bool plus_char, char *var, char **var_split)
{
char *tmp;

if (!plus_char)
ft_lstadd_back(g_glob->envp, ft_lstnew(ft_strdup(var)));
else
{
tmp = ft_strjoin(var_split[0], var_split[1]);
ft_lstadd_back(g_glob->envp, \
ft_lstnew(ft_strdup(ft_strjoin(var_split[0], \
var_split[1]))));
ft_lstnew(ft_strdup(tmp)));
free(tmp);
}
}

void edit_var(bool plus_char, char *var, char **var_split, t_list *env_cpy)
Expand Down

0 comments on commit a9c36eb

Please sign in to comment.