mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix: heredoc leak
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/06 15:14:32 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:54:27 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -58,6 +58,7 @@ typedef enum s_quote
|
|||||||
*/
|
*/
|
||||||
size_t strlen_till_char(char *s, int c);
|
size_t strlen_till_char(char *s, int c);
|
||||||
|
|
||||||
|
int ft_ischevron(int c);
|
||||||
bool check_quote(char *readline);
|
bool check_quote(char *readline);
|
||||||
bool check_syntax(char *readline);
|
bool check_syntax(char *readline);
|
||||||
bool check_redir(t_list *redir);
|
bool check_redir(t_list *redir);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/07 16:02:40 by mmoussou #+# #+# */
|
/* Created: 2023/11/07 16:02:40 by mmoussou #+# #+# */
|
||||||
/* Updated: 2023/11/08 17:02:57 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/10 13:57:35 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,6 +16,8 @@ t_list *ft_lstnew(void *content)
|
|||||||
{
|
{
|
||||||
t_list *r;
|
t_list *r;
|
||||||
|
|
||||||
|
if (!content || !*content)
|
||||||
|
return (NULL);
|
||||||
r = malloc(sizeof(t_list));
|
r = malloc(sizeof(t_list));
|
||||||
if (!r)
|
if (!r)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
/* Created: 2024/05/20 09:19:39 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/06 15:18:02 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 12:42:44 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
t_list **get_list2(t_list **list);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* # mode
|
* # mode
|
||||||
* 0: ouvre un nouveau fichier
|
* 0: ouvre un nouveau fichier
|
||||||
@ -77,6 +79,7 @@ void __forked(char *delimiter, int fd)
|
|||||||
get_input(delimiter, fd);
|
get_input(delimiter, fd);
|
||||||
ft_envclear(get_env(NULL), free);
|
ft_envclear(get_env(NULL), free);
|
||||||
ft_lstclear(get_list(NULL), free);
|
ft_lstclear(get_list(NULL), free);
|
||||||
|
ft_lstclear(get_list2(NULL), free_cmd);
|
||||||
ft_free("a", (char ***)get_void(NULL));
|
ft_free("a", (char ***)get_void(NULL));
|
||||||
rl_clear_history();
|
rl_clear_history();
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/10 01:14:10 by adjoly #+# #+# */
|
/* Created: 2024/07/10 01:14:10 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/06 15:18:19 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 12:43:36 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,6 +15,8 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
t_list **get_list2(t_list **list);
|
||||||
|
|
||||||
int __open_fd_here(char *path, int mode)
|
int __open_fd_here(char *path, int mode)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -67,6 +69,7 @@ void __heredoc_sig(int code)
|
|||||||
(void)code;
|
(void)code;
|
||||||
ft_envclear(get_env(NULL), free);
|
ft_envclear(get_env(NULL), free);
|
||||||
ft_lstclear(get_list(NULL), free);
|
ft_lstclear(get_list(NULL), free);
|
||||||
|
ft_lstclear(get_list2(NULL), free_cmd);
|
||||||
ft_free("a", (char ***)get_void(NULL));
|
ft_free("a", (char ***)get_void(NULL));
|
||||||
close(get_fd_heredoc(-1));
|
close(get_fd_heredoc(-1));
|
||||||
close(get_fd_heredoc(-1));
|
close(get_fd_heredoc(-1));
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/06 17:08:09 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 13:16:30 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/09 16:32:21 by adjoly #+# #+# */
|
/* Created: 2024/07/09 16:32:21 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/05 22:02:00 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:44:56 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ bool check_redir(t_list *list)
|
|||||||
while (tmp)
|
while (tmp)
|
||||||
{
|
{
|
||||||
redir = (t_redir *)tmp->content;
|
redir = (t_redir *)tmp->content;
|
||||||
if (redir->fd < 0)
|
if (redir->fd < 0 && redir->fd != -2)
|
||||||
return (send_error_parsing(ERROR_NO_FILE));
|
return (send_error_parsing(ERROR_NO_FILE));
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
|
17
src/parsing/ft_ischevron.c
Normal file
17
src/parsing/ft_ischevron.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ischevron.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/08/10 17:53:56 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/08/10 17:53:59 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
int ft_ischevron(int c)
|
||||||
|
{
|
||||||
|
return (c == '<' || c == '>');
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/05 13:48:57 by adjoly #+# #+# */
|
/* Created: 2024/06/05 13:48:57 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/06 17:23:12 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:54:35 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,11 +14,6 @@
|
|||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int ft_ischevron(int c)
|
|
||||||
{
|
|
||||||
return (c == '<' || c == '>');
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t __get_len_arg(char *s)
|
size_t __get_len_arg(char *s)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
@ -69,21 +64,12 @@ size_t __count_args(char *s)
|
|||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **split_argv(char *readline)
|
char **__split_argv(char *tmp)
|
||||||
{
|
{
|
||||||
char **argv;
|
char **argv;
|
||||||
char **tmp_av;
|
char **tmp_av;
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
tmp = readline;
|
argv = ft_calloc(__count_args(tmp) + 1, sizeof(char *));
|
||||||
if (!readline)
|
|
||||||
return (NULL);
|
|
||||||
if (!*readline)
|
|
||||||
{
|
|
||||||
free(readline);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
argv = ft_calloc(__count_args(readline) + 1, sizeof(char *));
|
|
||||||
tmp_av = argv;
|
tmp_av = argv;
|
||||||
while (*tmp)
|
while (*tmp)
|
||||||
{
|
{
|
||||||
@ -97,6 +83,23 @@ char **split_argv(char *readline)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*tmp_av = NULL;
|
*tmp_av = NULL;
|
||||||
|
return (argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **split_argv(char *readline)
|
||||||
|
{
|
||||||
|
char **argv;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (!readline)
|
||||||
|
return (NULL);
|
||||||
|
if (!*readline)
|
||||||
|
{
|
||||||
|
free(readline);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
tmp = readline;
|
||||||
|
argv = __split_argv(tmp);
|
||||||
free(readline);
|
free(readline);
|
||||||
return (argv);
|
return (argv);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/05 14:19:35 by adjoly #+# #+# */
|
/* Created: 2024/08/05 14:19:35 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/06 17:25:14 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:47:07 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -38,11 +38,6 @@ t_list *__get_redir(char **content)
|
|||||||
{
|
{
|
||||||
tmp = ft_lstnew(__open_heredoc(*(content + 1)));
|
tmp = ft_lstnew(__open_heredoc(*(content + 1)));
|
||||||
ft_lstadd_back(&list, tmp);
|
ft_lstadd_back(&list, tmp);
|
||||||
if (((t_redir *)(tmp->content))->sign == ERROR)
|
|
||||||
{
|
|
||||||
ft_lstclear(&list, free_redir);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (sign != ERROR)
|
else if (sign != ERROR)
|
||||||
ft_lstadd_back(&list, ft_lstnew(__to_redir(*(content + 1), sign)));
|
ft_lstadd_back(&list, ft_lstnew(__to_redir(*(content + 1), sign)));
|
||||||
@ -83,6 +78,5 @@ t_cmd *__to_cmd(char **content)
|
|||||||
free(content);
|
free(content);
|
||||||
cmd->cmd = ft_strdup(cmd->argv[0]);
|
cmd->cmd = ft_strdup(cmd->argv[0]);
|
||||||
ft_lstclear(&redir, free);
|
ft_lstclear(&redir, free);
|
||||||
printcmd(cmd);
|
|
||||||
return (cmd);
|
return (cmd);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */
|
/* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/06 17:05:44 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:46:54 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,9 +14,11 @@
|
|||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
t_list **get_list2(t_list **list);
|
||||||
|
|
||||||
void *clear_all(t_list *cmd, t_list *piped)
|
void *clear_all(t_list *cmd, t_list *piped)
|
||||||
{
|
{
|
||||||
ft_lstclear(&cmd, free);
|
ft_lstclear(&cmd, free_cmd);
|
||||||
ft_lstclear(&piped, free);
|
ft_lstclear(&piped, free);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -38,6 +40,10 @@ t_list *tokenizer(char *readline, t_env *env)
|
|||||||
ft_lstadd_back(&cmd,
|
ft_lstadd_back(&cmd,
|
||||||
ft_lstnew(__to_cmd(split_argv(env_var_replace(tmp->content,
|
ft_lstnew(__to_cmd(split_argv(env_var_replace(tmp->content,
|
||||||
env)))));
|
env)))));
|
||||||
|
if (((t_cmd *)ft_lstlast(cmd)->content)->infile == -2)
|
||||||
|
return (clear_all(cmd, piped));
|
||||||
|
if (!cmd->next)
|
||||||
|
get_list2(&cmd);
|
||||||
if (!ft_lstlast(cmd)->content)
|
if (!ft_lstlast(cmd)->content)
|
||||||
return (clear_all(cmd, piped));
|
return (clear_all(cmd, piped));
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/18 13:08:56 by adjoly #+# #+# */
|
/* Created: 2024/07/18 13:08:56 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/18 13:09:15 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:53:22 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,3 +20,12 @@ char **get_rl(char **rl)
|
|||||||
ret = rl;
|
ret = rl;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_fd_heredoc(int in)
|
||||||
|
{
|
||||||
|
static int fd;
|
||||||
|
|
||||||
|
if (in != -1)
|
||||||
|
fd = in;
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/09 17:24:15 by adjoly #+# #+# */
|
/* Created: 2024/07/09 17:24:15 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/05 23:11:27 by adjoly ### ########.fr */
|
/* Updated: 2024/08/10 17:53:25 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -31,6 +31,15 @@ t_list **get_list(t_list **list)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_list **get_list2(t_list **list)
|
||||||
|
{
|
||||||
|
static t_list **ret;
|
||||||
|
|
||||||
|
if (list)
|
||||||
|
ret = list;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
void *get_void(void *in)
|
void *get_void(void *in)
|
||||||
{
|
{
|
||||||
static void *ret;
|
static void *ret;
|
||||||
@ -55,12 +64,3 @@ int get_exit_code(int in)
|
|||||||
exit_code += 256;
|
exit_code += 256;
|
||||||
return (exit_code);
|
return (exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_fd_heredoc(int in)
|
|
||||||
{
|
|
||||||
static int fd;
|
|
||||||
|
|
||||||
if (in != -1)
|
|
||||||
fd = in;
|
|
||||||
return (fd);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user