Author: Raphael Isemann Date: 2021-06-21T19:46:55+02:00 New Revision: c197cddb16b3ed0de98f80566f8fc47f78aee64c
URL: https://github.com/llvm/llvm-project/commit/c197cddb16b3ed0de98f80566f8fc47f78aee64c DIFF: https://github.com/llvm/llvm-project/commit/c197cddb16b3ed0de98f80566f8fc47f78aee64c.diff LOG: [lldb] Add support for escaping zsh arguments LLDB supports having globbing regexes in the process launch arguments that will be resolved using the user's shell. This requires that we pass the launch args to the shell and then read back the expanded arguments using LLDB's argdumper utility. As the shell will not just expand the globbing regexes but all special characters, we need to escape all non-globbing charcters such as $, &, <, >, etc. as those otherwise are interpreted and removed in the step where we expand the globbing characters. Also because the special characters are shell-specific, LLDB needs to maintain a list of all the characters that need to be escaped for each specific shell. This patch adds the list of special characters that need to be escaped for `zsh`. Without this patch on systems where `zsh` is the user's shell (like on all macOS systems) having any of these special characters in your arguments or path to the binary will cause the process launch to fail. E.g., `lldb -- ./calc 1<2` is failing without this patch. The same happens if the absolute path to `calc` is in a directory that contains for example parentheses or other special characters. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D104627 Added: Modified: lldb/source/Utility/Args.cpp lldb/unittests/Utility/ArgsTest.cpp Removed: ################################################################################ diff --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp index 60d0790c9d295..505eff2f8e137 100644 --- a/lldb/source/Utility/Args.cpp +++ b/lldb/source/Utility/Args.cpp @@ -386,6 +386,7 @@ std::string Args::GetShellSafeArgument(const FileSpec &shell, static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&"}, {ConstString("tcsh"), " '\"<>()&$"}, + {ConstString("zsh"), " '\"<>()&;\\|"}, {ConstString("sh"), " '\"<>()&"}}; // safe minimal set diff --git a/lldb/unittests/Utility/ArgsTest.cpp b/lldb/unittests/Utility/ArgsTest.cpp index cd62c08df31e4..0b153a8d5936a 100644 --- a/lldb/unittests/Utility/ArgsTest.cpp +++ b/lldb/unittests/Utility/ArgsTest.cpp @@ -322,6 +322,12 @@ TEST(ArgsTest, GetShellSafeArgument) { EXPECT_EQ(Args::GetShellSafeArgument(bash, "a\""), "a\\\""); EXPECT_EQ(Args::GetShellSafeArgument(bash, "a\"b"), "a\\\"b"); + FileSpec zsh("/bin/zsh", FileSpec::Style::posix); + EXPECT_EQ(Args::GetShellSafeArgument(zsh, R"('";()<>&|\)"), + R"(\'\"\;\(\)\<\>\&\|\\)"); + // Normal characters and expressions that shouldn't be escaped. + EXPECT_EQ(Args::GetShellSafeArgument(zsh, "aA$1*"), "aA$1*"); + // String that doesn't need to be escaped EXPECT_EQ(Args::GetShellSafeArgument(bash, "a"), "a"); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits