Corrupted last error after deprecated/unsupported API calls #19003

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

Originally created by @alabuzhev on GitHub (Dec 2, 2022).

Windows Terminal version

No response

Windows build number

10.0.19044.2006

Other Software

No response

Steps to reproduce

Basically the problem is nicely described in this SO answer.

3c78e01ab5/src/server/ApiDispatchersInternal.cpp (L22)
ServerDeprecatedApi uses E_NOTIMPL (0x80004001), which on its way to the caller suffers several transformations and becomes 0x00004001, which is not a valid Windows error code.

It is quite unfortunate, given that the whole idea is to make it clear to the caller that the call is deprecated/not implemented.

Perhaps the function could use a different code that won't get fubared beyond recognition?
Given that it is passed to RtlNtStatusToDosError on its way, it probably should be NTSTATUS in the first place, either just raw STATUS_NOT_IMPLEMENTED or packed into HRESULT as HRESULT_FROM_NT(STATUS_NOT_IMPLEMENTED).

Expected Behavior

After an unsupported call:

  • GetLastError() should return a sensible value, e.g. ERROR_INVALID_FUNCTION or ERROR_CALL_NOT_IMPLEMENTED
  • (optionally) RtlGetLastNtStatus() should return a sensible value, e.g. STATUS_NOT_IMPLEMENTED

Actual Behavior

  • GetLastError() returns 0x0004001, which is an invalid error code.
  • RtlGetLastNtStatus() returns 0xC0074001, which is the same invalid win32 error code with STATUS_SEVERITY_ERROR and FACILITY_NTWIN32 bits.
Originally created by @alabuzhev on GitHub (Dec 2, 2022). ### Windows Terminal version _No response_ ### Windows build number 10.0.19044.2006 ### Other Software _No response_ ### Steps to reproduce Basically the problem is nicely described in [this SO answer](https://stackoverflow.com/a/61475022). https://github.com/microsoft/terminal/blob/3c78e01ab5a025290b8953a6dc0f2695c76c223e/src/server/ApiDispatchersInternal.cpp#L22 `ServerDeprecatedApi` uses `E_NOTIMPL` (0x80004001), which on its way to the caller suffers several transformations and becomes 0x00004001, which is not a valid Windows error code. It is quite unfortunate, given that the whole idea is to make it clear to the caller that the call is deprecated/not implemented. Perhaps the function could use a different code that won't get fubared beyond recognition? Given that it is passed to `RtlNtStatusToDosError` on its way, it probably should be `NTSTATUS` in the first place, either just raw `STATUS_NOT_IMPLEMENTED` or packed into HRESULT as `HRESULT_FROM_NT(STATUS_NOT_IMPLEMENTED)`. ### Expected Behavior After an unsupported call: - `GetLastError()` should return a sensible value, e.g. `ERROR_INVALID_FUNCTION` or `ERROR_CALL_NOT_IMPLEMENTED` - (optionally) `RtlGetLastNtStatus()` should return a sensible value, e.g. `STATUS_NOT_IMPLEMENTED` ### Actual Behavior - `GetLastError()` returns 0x0004001, which is an invalid error code. - `RtlGetLastNtStatus()` returns 0xC0074001, which is the same invalid win32 error code with `STATUS_SEVERITY_ERROR` and `FACILITY_NTWIN32` bits.
claunia added the Help WantedProduct-ConhostIssue-BugPriority-3Area-Server labels 2026-01-31 06:30:52 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19003