mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-11 04:38:24 -06: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 ## Validation Steps Performed * Launch with `"elevate": false` * Set `"elevate": true` * Duplicate a tab * Doesn't crash ✅
This commit is contained in:
parent
a38388615e
commit
427b37c07d
@ -4242,26 +4242,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()));
|
||||
|
||||
newTerminalArgs.StartingDirectory(_evaluatePathForCwd(controlSettings.DefaultSettings().StartingDirectory()));
|
||||
|
||||
_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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user