Skip to content

Commit

Permalink
Ignore newTab actions with a profile index greater than the number …
Browse files Browse the repository at this point in the history
…of profiles (#11621)

## Summary of the Pull Request

As discussed in team sync. Ignore `newTab` actions with a profile index greater than the number of profiles.

## PR Checklist
* [x] Closes #11114
* [x] I work here
* [ ] Tests added/passed
* [ ] Requires documentation to be updated - maybe❓
  • Loading branch information
zadjii-msft authored May 5, 2022
1 parent cd86c0f commit ce850ca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ namespace winrt::TerminalApp::implementation
}
else if (const auto& realArgs = args.ActionArgs().try_as<SplitPaneArgs>())
{
if (const auto& newTerminalArgs{ realArgs.TerminalArgs() })
{
if (const auto index = realArgs.TerminalArgs().ProfileIndex())
{
if (gsl::narrow<uint32_t>(index.Value()) >= _settings.ActiveProfiles().Size())
{
args.Handled(false);
return;
}
}
}

_SplitPane(realArgs.SplitDirection(),
// This is safe, we're already filtering so the value is (0, 1)
::base::saturated_cast<float>(realArgs.SplitSize()),
Expand Down Expand Up @@ -305,6 +317,18 @@ namespace winrt::TerminalApp::implementation
}
else if (const auto& realArgs = args.ActionArgs().try_as<NewTabArgs>())
{
if (const auto& newTerminalArgs{ realArgs.TerminalArgs() })
{
if (const auto index = newTerminalArgs.ProfileIndex())
{
if (gsl::narrow<uint32_t>(index.Value()) >= _settings.ActiveProfiles().Size())
{
args.Handled(false);
return;
}
}
}

LOG_IF_FAILED(_OpenNewTab(realArgs.TerminalArgs()));
args.Handled(true);
}
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ namespace winrt::TerminalApp::implementation
try
{
const auto profile{ _settings.GetProfileForArgs(newTerminalArgs) };
// GH#11114: GetProfileForArgs can return null if the index is higher
// than the number of available profiles.
if (!profile)
{
return S_FALSE;
}
const auto settings{ TerminalSettings::CreateWithNewTerminalArgs(_settings, newTerminalArgs, *_bindings) };

// Try to handle auto-elevation
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@ Model::Profile CascadiaSettings::GetProfileForArgs(const Model::NewTerminalArgs&
{
return profile;
}
else
{
// GH#11114 - Return NOTHING if they asked for a profile index
// outside the range of available profiles.
// Really, the caller should check this beforehand
return nullptr;
}
}

if (const auto commandLine = newTerminalArgs.Commandline(); !commandLine.empty())
Expand Down

0 comments on commit ce850ca

Please sign in to comment.