mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 00:48:23 -06:00
Avoid generating SSH profiles using stale memory (#19354)
You can't return a `string_view` to a temporary. It's a miracle this ever worked. Broken since inception in a5f9c85c39 Closes #19355
This commit is contained in:
parent
0aee174e68
commit
46b9572e60
@ -35,19 +35,14 @@ using namespace winrt::Microsoft::Terminal::Settings::Model;
|
||||
|
||||
/*static*/ const std::wregex SshHostGenerator::_configKeyValueRegex{ LR"(^\s*(\w+)\s+([^\s]+.*[^\s])\s*$)" };
|
||||
|
||||
/*static*/ std::wstring_view SshHostGenerator::_getProfileName(const std::wstring_view& hostName) noexcept
|
||||
winrt::hstring _getProfileName(const std::wstring_view& hostName) noexcept
|
||||
{
|
||||
return std::wstring_view{ L"" + PROFILE_TITLE_PREFIX + hostName };
|
||||
return winrt::hstring{ fmt::format(FMT_COMPILE(L"{0}{1}"), PROFILE_TITLE_PREFIX, hostName) };
|
||||
}
|
||||
|
||||
/*static*/ std::wstring_view SshHostGenerator::_getProfileIconPath() noexcept
|
||||
winrt::hstring _getProfileCommandLine(const std::wstring_view& sshExePath, const std::wstring_view& hostName) noexcept
|
||||
{
|
||||
return PROFILE_ICON_PATH;
|
||||
}
|
||||
|
||||
/*static*/ std::wstring_view SshHostGenerator::_getProfileCommandLine(const std::wstring_view& sshExePath, const std::wstring_view& hostName) noexcept
|
||||
{
|
||||
return std::wstring_view{ L"\"" + sshExePath + L"\" " + hostName };
|
||||
return winrt::hstring{ fmt::format(FMT_COMPILE(LR"("{0}" {1})"), sshExePath, hostName) };
|
||||
}
|
||||
|
||||
/*static*/ bool SshHostGenerator::_tryFindSshExePath(std::wstring& sshExePath) noexcept
|
||||
@ -164,8 +159,8 @@ void SshHostGenerator::GenerateProfiles(std::vector<winrt::com_ptr<implementatio
|
||||
{
|
||||
const auto profile{ CreateDynamicProfile(_getProfileName(hostName)) };
|
||||
|
||||
profile->Commandline(winrt::hstring{ _getProfileCommandLine(sshExePath, hostName) });
|
||||
profile->Icon(winrt::hstring{ _getProfileIconPath() });
|
||||
profile->Commandline(_getProfileCommandLine(sshExePath, hostName));
|
||||
profile->Icon(winrt::hstring{ PROFILE_ICON_PATH });
|
||||
|
||||
profiles.emplace_back(profile);
|
||||
}
|
||||
|
||||
@ -31,10 +31,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model
|
||||
private:
|
||||
static const std::wregex _configKeyValueRegex;
|
||||
|
||||
static std::wstring_view _getProfileName(const std::wstring_view& hostName) noexcept;
|
||||
static std::wstring_view _getProfileIconPath() noexcept;
|
||||
static std::wstring_view _getProfileCommandLine(const std::wstring_view& sshExePath, const std::wstring_view& hostName) noexcept;
|
||||
|
||||
static bool _tryFindSshExePath(std::wstring& sshExePath) noexcept;
|
||||
static bool _tryParseConfigKeyValue(const std::wstring_view& line, std::wstring& key, std::wstring& value) noexcept;
|
||||
static void _getHostNamesFromConfigFile(const std::wstring_view& configPath, std::vector<std::wstring>& hostNames) noexcept;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user