From: Dominik Kaiser Date: Fri, 13 Sep 2024 14:23:04 +0000 (+0200) Subject: Fix SEGV on invalid redirection X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=f24b063f2135f495193dac4847b9f2489d1d954a;p=42%2Fminishell.git Fix SEGV on invalid redirection --- 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 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 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) {