Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash when duplicating tabs with elevate:true #15548

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
return false;
}

newTerminalArgs.StartingDirectory(_evaluatePathForCwd(controlSettings.DefaultSettings().StartingDirectory()));
const auto defaultSettings = controlSettings.DefaultSettings();

_OpenElevatedWT(newTerminalArgs);
return true;
// 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;
}
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:
Expand Down