Author: Med Ismail Bennani Date: 2021-08-11T17:03:20+01:00 New Revision: be556d5131d56f285e55b0548f3b953d55d055c4
URL: https://github.com/llvm/llvm-project/commit/be556d5131d56f285e55b0548f3b953d55d055c4 DIFF: https://github.com/llvm/llvm-project/commit/be556d5131d56f285e55b0548f3b953d55d055c4.diff LOG: [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 <medismail.benn...@gmail.com> Added: Modified: lldb/source/Commands/CommandObjectProcess.cpp Removed: ################################################################################ diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 7aaba37315000..1a8ed021b9f0e 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -170,8 +170,6 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach { 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 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach { 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); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits