Skip to content

Commit be556d5

Browse files
committed
[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 <[email protected]>
1 parent 885be62 commit be556d5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
170170
if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result))
171171
return false;
172172

173-
llvm::StringRef target_settings_argv0 = target->GetArg0();
174-
175173
// Determine whether we will disable ASLR or leave it in the default state
176174
// (i.e. enabled if the platform supports it). First check if the process
177175
// launch options explicitly turn on/off
@@ -216,6 +214,8 @@ class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach {
216214
m_options.launch_info.GetEnvironment().insert(target_env.begin(),
217215
target_env.end());
218216

217+
llvm::StringRef target_settings_argv0 = target->GetArg0();
218+
219219
if (!target_settings_argv0.empty()) {
220220
m_options.launch_info.GetArguments().AppendArgument(
221221
target_settings_argv0);

0 commit comments

Comments
 (0)