Skip to content

Commit 24805c2

Browse files
yuvald-sweet-securitytstellar
authored andcommitted
[lldb] Use correct path for lldb-server executable (llvm#131519)
Hey, This solves an issue where running lldb-server-20 with a non-absolute path (for example, when it's installed into `/usr/bin` and the user runs it as `lldb-server-20 ...` and not `/usr/bin/lldb-server-20 ...`) fails with `error: spawn_process failed: execve failed: No such file or directory`. The underlying issue is that when run that way, it attempts to execute a binary named `lldb-server-20` from its current directory. This is also a mild security hazard because lldb-server is often being run as root in the directory /tmp, meaning that an unprivileged user can create the file /tmp/lldb-server-20 and lldb-server will execute it as root. (although, well, it's a debugging server we're talking about, so that may not be a real concern) I haven't previously contributed to this project; if you want me to change anything in the code please don't hesitate to let me know. (cherry picked from commit 945c494)
1 parent 182e8b7 commit 24805c2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lldb/tools/lldb-server/lldb-platform.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
3232
#include "lldb/Host/ConnectionFileDescriptor.h"
3333
#include "lldb/Host/HostGetOpt.h"
34+
#include "lldb/Host/HostInfo.h"
3435
#include "lldb/Host/MainLoop.h"
3536
#include "lldb/Host/OptionParser.h"
3637
#include "lldb/Host/Socket.h"
@@ -256,8 +257,9 @@ static void client_handle(GDBRemoteCommunicationServerPlatform &platform,
256257
printf("Disconnected.\n");
257258
}
258259

259-
static Status spawn_process(const char *progname, const Socket *conn_socket,
260-
uint16_t gdb_port, const lldb_private::Args &args,
260+
static Status spawn_process(const char *progname, const FileSpec &prog,
261+
const Socket *conn_socket, uint16_t gdb_port,
262+
const lldb_private::Args &args,
261263
const std::string &log_file,
262264
const StringRef log_channels, MainLoop &main_loop) {
263265
Status error;
@@ -267,9 +269,10 @@ static Status spawn_process(const char *progname, const Socket *conn_socket,
267269

268270
ProcessLaunchInfo launch_info;
269271

270-
FileSpec self_spec(progname, FileSpec::Style::native);
271-
launch_info.SetExecutableFile(self_spec, true);
272+
launch_info.SetExecutableFile(prog, false);
273+
launch_info.SetArg0(progname);
272274
Args &self_args = launch_info.GetArguments();
275+
self_args.AppendArgument(progname);
273276
self_args.AppendArgument(llvm::StringRef("platform"));
274277
self_args.AppendArgument(llvm::StringRef("--child-platform-fd"));
275278
self_args.AppendArgument(llvm::to_string(shared_socket.GetSendableFD()));
@@ -551,9 +554,10 @@ int main_platform(int argc, char *argv[]) {
551554
log_channels, &main_loop,
552555
&platform_handles](std::unique_ptr<Socket> sock_up) {
553556
printf("Connection established.\n");
554-
Status error = spawn_process(progname, sock_up.get(),
555-
gdbserver_port, inferior_arguments,
556-
log_file, log_channels, main_loop);
557+
Status error = spawn_process(
558+
progname, HostInfo::GetProgramFileSpec(), sock_up.get(),
559+
gdbserver_port, inferior_arguments, log_file, log_channels,
560+
main_loop);
557561
if (error.Fail()) {
558562
Log *log = GetLog(LLDBLog::Platform);
559563
LLDB_LOGF(log, "spawn_process failed: %s", error.AsCString());

0 commit comments

Comments
 (0)