mirror of
https://github.com/microsoft/terminal.git
synced 2026-04-13 09:41:02 +00:00
Fix a crash when duplicating tabs with elevate:true (#15548)
When `elevate` is set to `true`, `_maybeElevate` would try to
modify `newTerminalArgs` and crash, because during tab duplication
there aren't any `newTerminalArgs`. This issue may happen for instance
when receiving hand-off from a non-elevated client and then trying
to duplicate that tab.
Closes #15534
* Launch with `"elevate": false`
* Set `"elevate": true`
* Duplicate a tab
* Doesn't crash ✅
(cherry picked from commit 427b37c07d)
Service-Card-Id: 89534064
Service-Version: 1.17
This commit is contained in:
committed by
Dustin Howett
parent
c3bdf74538
commit
005af47054
@@ -4174,23 +4174,29 @@ namespace winrt::TerminalApp::implementation
|
||||
const TerminalSettingsCreateResult& controlSettings,
|
||||
const Profile& profile)
|
||||
{
|
||||
// Try to handle auto-elevation
|
||||
const auto requestedElevation = controlSettings.DefaultSettings().Elevate();
|
||||
const auto currentlyElevated = IsRunningElevated();
|
||||
|
||||
// We aren't elevated, but we want to be.
|
||||
if (requestedElevation && !currentlyElevated)
|
||||
// When duplicating a tab there aren't any newTerminalArgs.
|
||||
if (!newTerminalArgs)
|
||||
{
|
||||
// Manually set the Profile of the NewTerminalArgs to the guid we've
|
||||
// resolved to. If there was a profile in the NewTerminalArgs, this
|
||||
// will be that profile's GUID. If there wasn't, then we'll use
|
||||
// whatever the default profile's GUID is.
|
||||
|
||||
newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid()));
|
||||
_OpenElevatedWT(newTerminalArgs);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
const auto defaultSettings = controlSettings.DefaultSettings();
|
||||
|
||||
// If we don't even want to elevate we can return early.
|
||||
// If we're already elevated we can also return, because it doesn't get any more elevated than that.
|
||||
if (!defaultSettings.Elevate() || IsRunningElevated())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Manually set the Profile of the NewTerminalArgs to the guid we've
|
||||
// resolved to. If there was a profile in the NewTerminalArgs, this
|
||||
// will be that profile's GUID. If there wasn't, then we'll use
|
||||
// whatever the default profile's GUID is.
|
||||
newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid()));
|
||||
newTerminalArgs.StartingDirectory(_evaluatePathForCwd(defaultSettings.StartingDirectory()));
|
||||
_OpenElevatedWT(newTerminalArgs);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
||||
Reference in New Issue
Block a user