Skip to content

Commit 07a722c

Browse files
TeemperorJDevlieghere
authored andcommitted
[lldb] Escape semicolons for all shells
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 missing semicolon character to the escape list for all currently supported shells. Without this having a semicolon in the binary path or having a semicolon in the launch arguments will cause the argdumping process to fail. E.g., lldb -- ./calc "a;b" was failing before but is working now. Fixes rdar://55776943 Differential revision: https://reviews.llvm.org/D104629
1 parent 0e1f4d4 commit 07a722c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lldb/source/Utility/Args.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ std::string Args::GetShellSafeArgument(const FileSpec &shell,
384384
llvm::StringRef m_escapables;
385385
};
386386

387-
static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&"},
388-
{ConstString("tcsh"), " '\"<>()&$"},
387+
static ShellDescriptor g_Shells[] = {{ConstString("bash"), " '\"<>()&;"},
388+
{ConstString("tcsh"), " '\"<>()&$;"},
389389
{ConstString("zsh"), " '\"<>()&;\\|"},
390-
{ConstString("sh"), " '\"<>()&"}};
390+
{ConstString("sh"), " '\"<>()&;"}};
391391

392392
// safe minimal set
393393
llvm::StringRef escapables = " '\"";

lldb/unittests/Utility/ArgsTest.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,25 @@ TEST(ArgsTest, GetShellSafeArgument) {
328328
// Normal characters and expressions that shouldn't be escaped.
329329
EXPECT_EQ(Args::GetShellSafeArgument(zsh, "aA$1*"), "aA$1*");
330330

331-
// String that doesn't need to be escaped
332-
EXPECT_EQ(Args::GetShellSafeArgument(bash, "a"), "a");
331+
// Test escaping bash special characters.
332+
EXPECT_EQ(Args::GetShellSafeArgument(bash, R"( '"<>()&;)"),
333+
R"(\ \'\"\<\>\(\)\&\;)");
334+
// Normal characters and globbing expressions that shouldn't be escaped.
335+
EXPECT_EQ(Args::GetShellSafeArgument(bash, "aA$1*"), "aA$1*");
333336

334-
// Try escaping with tcsh and the tcsh-specific "$" escape.
337+
// Test escaping tcsh special characters.
335338
FileSpec tcsh("/bin/tcsh", FileSpec::Style::posix);
336-
EXPECT_EQ(Args::GetShellSafeArgument(tcsh, "a$b"), "a\\$b");
337-
// Bash however doesn't need escaping for "$".
338-
EXPECT_EQ(Args::GetShellSafeArgument(bash, "a$b"), "a$b");
339+
EXPECT_EQ(Args::GetShellSafeArgument(tcsh, R"( '"<>()&$;)"),
340+
R"(\ \'\"\<\>\(\)\&\$\;)");
341+
// Normal characters and globbing expressions that shouldn't be escaped.
342+
EXPECT_EQ(Args::GetShellSafeArgument(tcsh, "aA1*"), "aA1*");
343+
344+
// Test escaping sh special characters.
345+
FileSpec sh("/bin/sh", FileSpec::Style::posix);
346+
EXPECT_EQ(Args::GetShellSafeArgument(sh, R"( '"<>()&;)"),
347+
R"(\ \'\"\<\>\(\)\&\;)");
348+
// Normal characters and globbing expressions that shouldn't be escaped.
349+
EXPECT_EQ(Args::GetShellSafeArgument(sh, "aA$1*"), "aA$1*");
339350

340351
// Try escaping with an unknown shell.
341352
FileSpec unknown_shell("/bin/unknown_shell", FileSpec::Style::posix);

0 commit comments

Comments
 (0)