diff --git a/lldb/source/Host/windows/ProcessLauncherWindows.cpp b/lldb/source/Host/windows/ProcessLauncherWindows.cpp --- a/lldb/source/Host/windows/ProcessLauncherWindows.cpp +++ b/lldb/source/Host/windows/ProcessLauncherWindows.cpp @@ -23,10 +23,8 @@ namespace { void CreateEnvironmentBuffer(const Environment &env, std::vector &buffer) { - if (env.size() == 0) - return; - - // Environment buffer is a null terminated list of null terminated strings + // Environment buffer is a list of null-terminated list of strings. It ends + // with a double null. for (const auto &KV : env) { std::wstring warg; if (llvm::ConvertUTF8toWide(Environment::compose(KV), warg)) { @@ -38,6 +36,12 @@ // One null wchar_t (to end the block) is two null bytes buffer.push_back(0); buffer.push_back(0); + // If the environment was empty, we must insert an extra byte to ensure a + // double null. + if (env.empty()) { + buffer.push_back(0); + buffer.push_back(0); + } } bool GetFlattenedWindowsCommandString(Args args, std::string &command) { @@ -94,8 +98,7 @@ LPVOID env_block = nullptr; ::CreateEnvironmentBuffer(launch_info.GetEnvironment(), environment); - if (!environment.empty()) - env_block = environment.data(); + env_block = environment.data(); executable = launch_info.GetExecutableFile().GetPath(); GetFlattenedWindowsCommandString(launch_info.GetArguments(), commandLine); diff --git a/lldb/test/API/commands/settings/TestSettings.py b/lldb/test/API/commands/settings/TestSettings.py --- a/lldb/test/API/commands/settings/TestSettings.py +++ b/lldb/test/API/commands/settings/TestSettings.py @@ -286,7 +286,6 @@ "Environment variable 'MY_ENV_VAR' successfully passed."]) @skipIfRemote # it doesn't make sense to send host env to remote target - @skipIf(oslist=["windows"]) def test_pass_host_env_vars(self): """Test that the host env vars are passed to the launched process.""" self.build()