fix: segfault '<t'

This commit is contained in:
starnakin 2023-07-05 00:36:53 +02:00
parent 3cc5d4cdce
commit e9e80c192e
3 changed files with 25 additions and 23 deletions

View File

@ -5,7 +5,8 @@ void cmd_del(void *ptr)
cmd_t* content = ptr; cmd_t* content = ptr;
tab_free((void**)content->args); tab_free((void**)content->args);
free(content->executable); if (content->executable)
free(content->executable);
free(content); free(content);
} }
@ -16,6 +17,7 @@ int cmd_init(cmd_t* command)
command->input[1] = -1; command->input[1] = -1;
command->output[0] = -1; command->output[0] = -1;
command->output[1] = -1; command->output[1] = -1;
command->executable = NULL;
return 0; return 0;
} }

View File

@ -14,11 +14,6 @@
int execute(lst** cmds, cmd_t* cmd, lst** env) int execute(lst** cmds, cmd_t* cmd, lst** env)
{ {
int pid; int pid;
if (cmd->input[0] == -2 || cmd->input[0] == -2)
{
pid = -1;
return 0;
}
if (cmd->executable == NULL) if (cmd->executable == NULL)
{ {
dprintf(2, "zzsh: command not found: %s\n", cmd->args[0]); 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(content->output, fds[1]);
add_fd(((cmd_t*)current->next->content)->input, fds[0]); 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)) if (execute(cmds, content, data->env))
{ {

View File

@ -19,29 +19,32 @@ int parsing_cmd(char *str, cmd_t* command, data_t *data)
command->args = split_quoted_charset(str, "\t "); command->args = split_quoted_charset(str, "\t ");
if (command->args == NULL) if (command->args == NULL)
return 1; 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]); quote_remover(command->args[i]);
if (command->args[0][0] == '\\') if (command->args[0] != NULL)
{ {
tmp = strdup(command->args[0] + 1); if (command->args[0][0] == '\\')
if (tmp != NULL)
{ {
free(command->args[0]); tmp = strdup(command->args[0] + 1);
command->args[0] = strdup(tmp); if (tmp != NULL)
{
free(command->args[0]);
command->args[0] = strdup(tmp);
}
} }
} else
else
{
tmp = get_alias(data->aliases, command->args[0]);
if (tmp != NULL)
{ {
free(command->args[0]); tmp = get_alias(data->aliases, command->args[0]);
command->args[0] = strdup(tmp); 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; return 0;
} }