From be556d5131d56f285e55b0548f3b953d55d055c4 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Wed, 11 Aug 2021 16:56:36 +0100 Subject: [lldb/Commands] Fix heap-use-after-free error in CommandObjectProcess This patch should fix the use-after-free error that was brought up by the LLDB ASAN Green Dragon bot. This is caused because the `StringRef` object was acquired too early before being use and by the underlying memory was modified which caused it to point to null memory. Fetching back the string reference close to its usage location should fix the issue. Signed-off-by: Med Ismail Bennani --- lldb/source/Commands/CommandObjectProcess.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lldb/source/Commands/CommandObjectProcess.cpp') diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 7aaba37..1a8ed02 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -170,8 +170,6 @@ protected: if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result)) return false; - llvm::StringRef target_settings_argv0 = target->GetArg0(); - // Determine whether we will disable ASLR or leave it in the default state // (i.e. enabled if the platform supports it). First check if the process // launch options explicitly turn on/off @@ -216,6 +214,8 @@ protected: m_options.launch_info.GetEnvironment().insert(target_env.begin(), target_env.end()); + llvm::StringRef target_settings_argv0 = target->GetArg0(); + if (!target_settings_argv0.empty()) { m_options.launch_info.GetArguments().AppendArgument( target_settings_argv0); -- cgit v1.1