From 5f1cc64504bb025c1240cc0bcef3eabeb3859a10 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sat, 26 Sep 2020 23:36:27 +0330 Subject: [PATCH] Shell: Fix use-after-move in alias resolution This unbreaks aliases! --- Shell/Shell.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 450293de70..57a99f429a 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -293,10 +293,12 @@ Vector Shell::expand_aliases(Vector initial_commands auto* ast = static_cast(subcommand_ast.ptr()); subcommand_ast = ast->command(); } - NonnullRefPtr substitute = adopt(*new AST::Join(subcommand_ast->position(), - subcommand_ast.release_nonnull(), - adopt(*new AST::CommandLiteral(subcommand_ast->position(), command)))); - for (auto& subst_command : substitute->run(*this)->resolve_as_commands(*this)) { + auto subcommand_nonnull = subcommand_ast.release_nonnull(); + NonnullRefPtr substitute = adopt(*new AST::Join(subcommand_nonnull->position(), + subcommand_nonnull, + adopt(*new AST::CommandLiteral(subcommand_nonnull->position(), command)))); + auto res = substitute->run(*this); + for (auto& subst_command : res->resolve_as_commands(*this)) { if (!subst_command.argv.is_empty() && subst_command.argv.first() == argv0) // Disallow an alias resolving to itself. commands.append(subst_command); else