JDevlieghere updated this revision to Diff 222759.
JDevlieghere marked an inline comment as done.
JDevlieghere added a comment.
Check pointer returned by `getpwuid`.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68316/new/
https://reviews.llvm.org/D68316
Files:
lldb/lit/Host/Inputs/simple.c
lldb/lit/Host/TestCustomShell.test
lldb/source/Host/posix/HostInfoPosix.cpp
Index: lldb/source/Host/posix/HostInfoPosix.cpp
===================================================================
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,14 @@
uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+ if (const char *v = ::getenv("SHELL"))
+ return FileSpec(v);
+ if (const auto *pw = ::getpwuid(::geteuid()))
+ if (const char *v = pw->pw_shell)
+ return FileSpec(v);
+ return FileSpec("/bin/sh");
+}
bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===================================================================
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===================================================================
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }
Index: lldb/source/Host/posix/HostInfoPosix.cpp
===================================================================
--- lldb/source/Host/posix/HostInfoPosix.cpp
+++ lldb/source/Host/posix/HostInfoPosix.cpp
@@ -113,7 +113,14 @@
uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }
-FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }
+FileSpec HostInfoPosix::GetDefaultShell() {
+ if (const char *v = ::getenv("SHELL"))
+ return FileSpec(v);
+ if (const auto *pw = ::getpwuid(::geteuid()))
+ if (const char *v = pw->pw_shell)
+ return FileSpec(v);
+ return FileSpec("/bin/sh");
+}
bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
return ComputePathRelativeToLibrary(file_spec, "/bin");
Index: lldb/lit/Host/TestCustomShell.test
===================================================================
--- /dev/null
+++ lldb/lit/Host/TestCustomShell.test
@@ -0,0 +1,5 @@
+# UNSUPPORTED: system-windows
+
+# RUN: %clang %S/Inputs/simple.c -g -o %t.out
+# RUN: SHELL=bogus %lldb %t.out -b -o 'run' 2>&1 | FileCheck %s
+# CHECK: error: shell expansion failed
Index: lldb/lit/Host/Inputs/simple.c
===================================================================
--- /dev/null
+++ lldb/lit/Host/Inputs/simple.c
@@ -0,0 +1 @@
+int main(int argc, char const *argv[]) { return 0; }
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits