microsoft / microsoft/terminal

CONSOLE_INFORMATION::IsConsoleLocked and CONSOLE_INFORMATION::GetCSRecursionCount inappropriately groveling into opaque CRITICAL_SECTION object internals

Open
#753 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Server Issue-Bug Product-Conhost
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

These two functions appear to be peering into the internal opaque CRITICAL_SECTION object. The CRITICAL_SECTION definition is opaque and shouldn't be used by apps (it can - and has - changed layout between OS versions so long as the size is the same).

The CONSOLE_INFORMATION object should track an owning thread ID and critical section entry count itself if it needs to get this information and shouldn't try to assume that it knows about the critical section implementation details (particularly for OSS'd code we'd like to avoid encouraging that sort of thing as it inevitably leads to broken apps on future OS updates etc.).

bool CONSOLE_INFORMATION::IsConsoleLocked() const
{​
// The critical section structure's OwningThread field contains the ThreadId despite having the HANDLE type.​
// This requires us to hard cast the ID to compare.​
return _csConsoleLock.OwningThread == (HANDLE)GetCurrentThreadId();​
}​


ULONG CONSOLE_INFORMATION::GetCSRecursionCount()​
{​
return _csConsoleLock.RecursionCount;​
}​

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating CONSOLE_INFORMATION::IsConsoleLocked and CONSOLE_INFORMATION::GetCSRecursionCount and reading their callers. Replace the dependence on CRITICAL_SECTION internals with ownership and recursion state tracked by CONSOLE_INFORMATION, then verify that the callers still receive the required lock information without inspecting the opaque object layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, operating-systems
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.