diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-09-26 23:36:27 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-26 22:11:28 +0200 |
commit | 5f1cc64504bb025c1240cc0bcef3eabeb3859a10 (patch) | |
tree | c3270eb40e43d5cddd9d2dd7a432b3fc197ca053 /Shell | |
parent | fa03a2848f70fadd91a4eb0aa10cf19a044b33a1 (diff) | |
download | serenity-5f1cc64504bb025c1240cc0bcef3eabeb3859a10.zip |
Shell: Fix use-after-move in alias resolution
This unbreaks aliases!
Diffstat (limited to 'Shell')
-rw-r--r-- | Shell/Shell.cpp | 10 |
1 files 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<AST::Command> Shell::expand_aliases(Vector<AST::Command> initial_commands auto* ast = static_cast<AST::Execute*>(subcommand_ast.ptr()); subcommand_ast = ast->command(); } - NonnullRefPtr<AST::Node> 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<AST::Node> 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 |