aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kaiser2024-09-13 16:23:04 +0200
committerDominik Kaiser2024-09-13 16:23:04 +0200
commitf24b063f2135f495193dac4847b9f2489d1d954a (patch)
treec4be92a4ea6ffb648af6ad9a53acc1e764198beb
parent61fe4e28bf95f782105a2907cd6fbfc196a6874b (diff)
downloadminishell-f24b063f2135f495193dac4847b9f2489d1d954a.tar.gz
minishell-f24b063f2135f495193dac4847b9f2489d1d954a.zip
Fix SEGV on invalid redirection
-rw-r--r--src/new_node.c14
-rw-r--r--src/print_ast.c6
2 files changed, 13 insertions, 7 deletions
diff --git a/src/new_node.c b/src/new_node.c
index 6da9f9e..5c770aa 100644
--- a/src/new_node.c
+++ b/src/new_node.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 11:21:03 by dkaiser #+# #+# */
-/* Updated: 2024/08/11 12:22:45 by dkaiser ### ########.fr */
+/* Updated: 2024/09/13 16:18:29 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,10 +43,14 @@ t_node *new_cmd_node(char **args, t_redirection redirs[2])
if (node == NULL)
return (NULL);
node->content.cmd.args = args;
- node->content.cmd.redirs[0] = redirs[0];
- node->content.cmd.redirs[1] = redirs[1];
- free(redirs);
- return (node);
+ if (redirs != NULL)
+ {
+ node->content.cmd.redirs[0] = redirs[0];
+ node->content.cmd.redirs[1] = redirs[1];
+ free(redirs);
+ return (node);
+ }
+ return (NULL);
}
t_node *new_string_node(char *string)
diff --git a/src/print_ast.c b/src/print_ast.c
index a511246..e1f0158 100644
--- a/src/print_ast.c
+++ b/src/print_ast.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/22 15:16:53 by dkaiser #+# #+# */
-/* Updated: 2024/08/11 12:26:00 by dkaiser ### ########.fr */
+/* Updated: 2024/09/13 16:21:32 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,7 +27,9 @@ void print_ast(t_node *ast)
static void print_ast_rec(t_node *ast, int indent)
{
- if (ast->type == CMD_NODE)
+ if (!ast)
+ panic("Parsing error");
+ else if (ast->type == CMD_NODE)
print_cmd_node(ast, indent);
else if (ast->type == PIPE_NODE)
{