From e9e80c192e667fecdd9973d4a5198becfa6c324e Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 5 Jul 2023 00:36:53 +0200 Subject: [PATCH] fix: segfault 'args); - free(content->executable); + if (content->executable) + free(content->executable); free(content); } @@ -16,6 +17,7 @@ int cmd_init(cmd_t* command) command->input[1] = -1; command->output[0] = -1; command->output[1] = -1; + command->executable = NULL; return 0; } diff --git a/src/exec/exec.c b/src/exec/exec.c index 79d2a93..4a3af89 100644 --- a/src/exec/exec.c +++ b/src/exec/exec.c @@ -14,11 +14,6 @@ int execute(lst** cmds, cmd_t* cmd, lst** env) { int pid; - if (cmd->input[0] == -2 || cmd->input[0] == -2) - { - pid = -1; - return 0; - } if (cmd->executable == NULL) { dprintf(2, "zzsh: command not found: %s\n", cmd->args[0]); @@ -127,7 +122,9 @@ int cmds_list_exec(lst** cmds, data_t *data) add_fd(content->output, fds[1]); add_fd(((cmd_t*)current->next->content)->input, fds[0]); } - if (builtin_execute(data, content) == 1) + if (content->input[0] == -2 || content->input[0] == -2 || content->args[0] == NULL) + content->pid = -1; + else if (builtin_execute(data, content) == 1) { if (execute(cmds, content, data->env)) { diff --git a/src/parsing/parsing.c b/src/parsing/parsing.c index 991b422..54eb1c4 100644 --- a/src/parsing/parsing.c +++ b/src/parsing/parsing.c @@ -19,29 +19,32 @@ int parsing_cmd(char *str, cmd_t* command, data_t *data) command->args = split_quoted_charset(str, "\t "); if (command->args == NULL) return 1; - for (size_t i = 0; command->args[i]; i++) + for (size_t i = 0; command->args[i] != NULL; i++) quote_remover(command->args[i]); - if (command->args[0][0] == '\\') + if (command->args[0] != NULL) { - tmp = strdup(command->args[0] + 1); - if (tmp != NULL) + if (command->args[0][0] == '\\') { - free(command->args[0]); - command->args[0] = strdup(tmp); + tmp = strdup(command->args[0] + 1); + if (tmp != NULL) + { + free(command->args[0]); + command->args[0] = strdup(tmp); + } } - } - else - { - tmp = get_alias(data->aliases, command->args[0]); - if (tmp != NULL) + else { - free(command->args[0]); - command->args[0] = strdup(tmp); + tmp = get_alias(data->aliases, command->args[0]); + if (tmp != NULL) + { + free(command->args[0]); + command->args[0] = strdup(tmp); + } } + if (command->args[0] == NULL) + return 1; + command->executable = parsing_executable(command->args[0], data); } - if (command->args[0] == NULL) - return 1; - command->executable = parsing_executable(command->args[0], data); return 0; }