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 infinite recursion in TSF #18248

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions src/tsf/Implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,20 @@ void Implementation::Uninitialize() noexcept
}
}

HWND Implementation::FindWindowOfActiveTSF() const noexcept
{
HWND Implementation::FindWindowOfActiveTSF() noexcept
{
// We don't know what ITfContextOwner we're going to get in
// the code below and it may very well be us (this instance).
// It's also possible that our IDataProvider's GetHwnd()
// implementation calls this FindWindowOfActiveTSF() function.
// This can result in infinite recursion because we're calling
// GetWnd() below, which may call GetHwnd(), which may call
// FindWindowOfActiveTSF(), and so on.
// By temporarily clearing the _provider we fix that flaw.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the determination to bail out made based on _provider?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout the file. All places that use _provider are already doing a null check.

const auto restore = wil::scope_exit([this, provider = std::move(_provider)]() mutable {
_provider = std::move(provider);
});

wil::com_ptr<IEnumTfDocumentMgrs> enumDocumentMgrs;
if (FAILED_LOG(_threadMgrEx->EnumDocumentMgrs(enumDocumentMgrs.addressof())))
{
Expand Down
2 changes: 1 addition & 1 deletion src/tsf/Implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft::Console::TSF

void Initialize();
void Uninitialize() noexcept;
HWND FindWindowOfActiveTSF() const noexcept;
HWND FindWindowOfActiveTSF() noexcept;
void AssociateFocus(IDataProvider* provider);
void Focus(IDataProvider* provider);
void Unfocus(IDataProvider* provider);
Expand Down
Loading