Malformed condrv request on SetConsoleNumberOfCommands call #20697

Open
opened 2026-01-31 07:21:30 +00:00 by claunia · 0 comments
Owner

Originally created by @o-sdn-o on GitHub (Oct 19, 2023).

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:
    08f30330d1/src/server/ApiDispatchers.cpp (L1520-L1541)
  • 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.

Originally created by @o-sdn-o on GitHub (Oct 19, 2023). ### 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`: https://github.com/microsoft/terminal/blob/08f30330d15e22adf23ee04164fc2474f290348a/src/server/ApiDispatchers.cpp#L1520-L1541 - Run the following C++20 code inside wt to trigger the breakpoint on SetConsoleNumberOfCommands call: ```c++ #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.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 07:21:30 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20697