Repository navigation
Closed
Labels
Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
Description
Windows Terminal version
current main branch
Windows build number
10.0.19045.3516
Other Software
No response
Steps to reproduce
Openconsole.exe receives malformed request from condrv during dispatching Win32 API SetConsoleNumberOfCommandsA/W call. The length of the exe name is always equals 6 (bytes). It is independent of the exe name string specified in the SetConsoleNumberOfCommands call. Even if the exe name consists of one character.
Repro:
- Build WT in debug configuration.
- Run WT with any cmd profile.
- Attach openconsole.exe process to visual studio debugger and set breakpoint at
src\server\ApiDispatchers.cpp:1529:
terminal/src/server/ApiDispatchers.cpp
Lines 1520 to 1541 in 08f3033
[[nodiscard]] HRESULT ApiDispatchers::ServerSetConsoleNumberOfCommands(_Inout_ CONSOLE_API_MSG* const m, _Inout_ BOOL* const /*pbReplyPending*/) { const auto a = &m->u.consoleMsgL3.SetConsoleNumberOfCommandsW; PVOID pvExeName; ULONG cbExeNameLength; RETURN_IF_FAILED(m->GetInputBuffer(&pvExeName, &cbExeNameLength)); const size_t NumberOfCommands = a->NumCommands; if (a->Unicode) { const std::wstring_view inputExeName(reinterpret_cast<wchar_t*>(pvExeName), cbExeNameLength / sizeof(wchar_t)); return m->_pApiRoutines->SetConsoleNumberOfCommandsWImpl(inputExeName, NumberOfCommands); } else { const std::string_view inputExeName(reinterpret_cast<char*>(pvExeName), cbExeNameLength); return m->_pApiRoutines->SetConsoleNumberOfCommandsAImpl(inputExeName, NumberOfCommands); } } - Run the following C++20 code inside wt to trigger the breakpoint on SetConsoleNumberOfCommands call:
#include <iostream>
#include <windows.h>
using namespace std::literals;
int main()
{
auto exe_a = "program_name.exe"s;
auto exe_w = L"program_name.exe"s;
using SetConsoleNumberOfCommandsA_ptr = std::decay<decltype(::SetConsoleNumberOfCommandsA)>::type;
using SetConsoleNumberOfCommandsW_ptr = std::decay<decltype(::SetConsoleNumberOfCommandsW)>::type;
auto kernel32_dll = ::LoadLibraryExA("kernel32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
auto NtSetConsoleNumberOfCommandsA = reinterpret_cast<SetConsoleNumberOfCommandsA_ptr>(::GetProcAddress(kernel32_dll, "SetConsoleNumberOfCommandsA"));
auto NtSetConsoleNumberOfCommandsW = reinterpret_cast<SetConsoleNumberOfCommandsW_ptr>(::GetProcAddress(kernel32_dll, "SetConsoleNumberOfCommandsW"));
auto rc_a = NtSetConsoleNumberOfCommandsA(10, exe_a.data());
auto rc_w = NtSetConsoleNumberOfCommandsW(10, exe_w.data());
std::cout << "rc_a="<< rc_a << " rc_w="<< rc_w << "\n";
}Expected Behavior
ULONG cbExeNameLength equals the exe name length in bytes.
Actual Behavior
ULONG cbExeNameLength always equals 6.
Metadata
Metadata
Assignees
Labels
Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
Activity
lhecker commentedon Oct 19, 2023
Is this perhaps an issue with Windows 10? It works fine on Windows 11
10.0.25962.1000. But I also don't think anything changed with that code since 19045...o-sdn-o commentedon Oct 19, 2023
Yes, this is on Windows 10.
o-sdn-o commentedon Oct 19, 2023
The problem is not in the WT/openconsole source code, the problem is in the unknown condrv code.
o-sdn-o commentedon Oct 19, 2023
Since this was fixed in Win11, this is no longer an issue at all. 😉
o-sdn-o commentedon Oct 19, 2023
I confirm, this works fine on Win11.
DHowett commentedon Oct 19, 2023
Ugh, I remember this one. The issue was actually over in conclnt (static lib in kernelbase).
Here's the commit message:
You can tell I'm the one who fixed it because it was needlessly wordy. 😅
Aaaand here's the diff for the SetConsoleNumberOfCommands issue:
The fix went out in Insider build
19611.1000.rs_prerelease.200415-1433... and using my decoder ring I learn that this means it only shipped in Windows 11+ 😄alexolog commentedon Oct 21, 2023
Will this be fixed for Win10?
DHowett commentedon Oct 23, 2023
No. We closed the book on Windows 10 a while ago, and low-severity bugs like this don't meet the bar for servicing the fix back to older versions of Windows... even though I wish that weren't the case.